Skip to content

Commit

Permalink
Goto: finding global vars types #13
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed May 16, 2024
1 parent b6196bc commit 419bbcc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/core/src/tokens/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,23 @@ pub enum Keyword {
Var,
VirtualParent,
While,
}

impl Keyword {
pub fn is_global_var(&self) -> bool {
use Keyword::*;
match self {
TheCamera
| TheDebug
| TheGame
| TheInput
| ThePlayer
| TheServer
| TheSound
| TheTelemetry
| TheTimer
| TheUI => true,
_ => false
}
}
}
13 changes: 13 additions & 0 deletions crates/lsp/src/providers/goto.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::str::FromStr;
use tower_lsp::lsp_types as lsp;
use tower_lsp::jsonrpc::Result;
use abs_path::AbsPath;
use witcherscript::ast::SyntaxNodeVisitorChain;
use witcherscript::tokens::Keyword;
use witcherscript_analysis::symbol_analysis::symbol_table::{SymbolLocation, marcher::IntoSymbolTableMarcher};
use witcherscript_analysis::symbol_analysis::symbol_path::SymbolPathBuf;
use witcherscript_analysis::symbol_analysis::symbols::*;
Expand Down Expand Up @@ -154,6 +156,17 @@ async fn inspect_symbol_at_position(backend: &Backend, content_path: &AbsPath, d
.and_then(|v| v.try_as_special_var_ref())
.map(|sym| sym.type_path().clone())
},
PositionTargetKind::DataIdentifier(name) => {
if Keyword::from_str(&name).map(|kw| kw.is_global_var()).unwrap_or(false) {
symtabs_marcher.clone()
.get(&SymbolPathBuf::new(&name, SymbolCategory::Data))
.and_then(|v| v.try_as_global_var_ref())
.map(|sym| sym.type_path().clone())
} else {
// not ready yet
None
}
}
// other stuff not reliably possible yet
_ => {
None
Expand Down

0 comments on commit 419bbcc

Please sign in to comment.