Skip to content

Commit

Permalink
Added global symbol search #53 #54
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed Aug 16, 2024
1 parent b30c31a commit dd4d013
Show file tree
Hide file tree
Showing 11 changed files with 661 additions and 4 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/analysis/src/symbol_analysis/symbol_table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl SymbolTable {
}


pub(crate) fn iter(&self) -> impl Iterator<Item = (&SymbolPath, &SymbolVariant)> {
pub fn iter(&self) -> impl Iterator<Item = (&SymbolPath, &SymbolVariant)> {
self.symbols.iter().map(|(p, v)| (p.as_sympath(), v))
}

Expand Down
5 changes: 5 additions & 0 deletions crates/analysis/src/symbol_analysis/symbols/enum_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ impl EnumVariantSymbol {
value: 0
}
}


pub fn parent_enum_name(&self) -> &str {
self.parent_enum_path.components().next().map(|c| c.name).unwrap_or_default()
}
}
3 changes: 2 additions & 1 deletion crates/lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ bitmask-enum.workspace = true
shrinkwraprs.workspace = true
filetime.workspace = true
tower-lsp = "0.20.0"
tokio = { version = "1.38", features = ["macros", "rt", "rt-multi-thread", "io-std", "time"] }
tokio = { version = "1.38", features = ["macros", "rt", "rt-multi-thread", "io-std", "time"] }
fuzzy-matcher = "0.3.7"
8 changes: 6 additions & 2 deletions crates/lsp/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use abs_path::AbsPath;
use witcherscript::{script_document::ScriptDocument, Script};
use witcherscript_analysis::symbol_analysis::symbol_table::{marcher::SymbolTableMarcher, SymbolTable};
use witcherscript_project::{ContentGraph, SourceTree, SourceTreePath};
use crate::{config::Config, reporting::Reporter};
use crate::{cache::Cache, config::Config, reporting::Reporter};



Expand All @@ -28,6 +28,8 @@ pub struct BackendInner {
// key is path to the file
pub scripts: Arc<ScriptStates>,
pub symtabs: RwLock<SymbolTables>,

pub cache: Cache
}

#[derive(Debug, Shrinkwrap)]
Expand Down Expand Up @@ -104,7 +106,9 @@ impl Backend {
content_graph: RwLock::new(ContentGraph::new()),
source_trees: SourceTreeMap::new(),
scripts: Arc::new(ScriptStates::new()),
symtabs: RwLock::new(SymbolTables::new())
symtabs: RwLock::new(SymbolTables::new()),

cache: Cache::new()
})
}
}
Expand Down
16 changes: 16 additions & 0 deletions crates/lsp/src/cache/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use tokio::sync::RwLock;

use crate::providers::workspace_symbols::WorkspaceSymbolCache;


pub struct Cache {
pub workspace_symbols: RwLock<WorkspaceSymbolCache>
}

impl Cache {
pub fn new() -> Self {
Self {
workspace_symbols: RwLock::new(WorkspaceSymbolCache::new())
}
}
}
5 changes: 5 additions & 0 deletions crates/lsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod providers;
mod config;
mod reporting;
mod tasks;
mod cache;
mod requests;
mod notifications;
mod model;
Expand Down Expand Up @@ -77,6 +78,10 @@ impl LanguageServer for Backend {
self.document_symbol_impl(params).await
}

async fn symbol(&self, params: lsp::WorkspaceSymbolParams) -> Result<Option<Vec<lsp::SymbolInformation>>> {
self.symbol_impl(params).await
}


async fn goto_definition(&self, params: lsp::GotoDefinitionParams) -> Result<Option<lsp::GotoDefinitionResponse>> {
self.goto_definition_impl(params).await
Expand Down
1 change: 1 addition & 0 deletions crates/lsp/src/providers/initialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ impl Backend {
}),
selection_range_provider: Some(lsp::SelectionRangeProviderCapability::Simple(true)),
document_symbol_provider: Some(lsp::OneOf::Left(true)),
workspace_symbol_provider: Some(lsp::OneOf::Left(true)),
definition_provider: Some(lsp::OneOf::Left(true)),
declaration_provider: Some(lsp::DeclarationCapability::Simple(true)),
type_definition_provider: Some(lsp::TypeDefinitionProviderCapability::Simple(true)),
Expand Down
1 change: 1 addition & 0 deletions crates/lsp/src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod selection_range;
pub mod document_symbols;
pub mod goto;
pub mod hover;
pub mod workspace_symbols;

pub mod custom;

Expand Down
Loading

0 comments on commit dd4d013

Please sign in to comment.