forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LSP: Collect declaration tokens from std lib prelude and dependencies (…
…FuelLabs#3212) We weren't collecting tokens imported by default with the new std lib prelude. This PR now collects these tokens so we can do things like show documentation for imported types on hover requests. closes FuelLabs#3208
- Loading branch information
1 parent
5f29c66
commit d818f14
Showing
11 changed files
with
234 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use crate::{ | ||
core::token::{AstToken, SymbolKind, Token, TokenMap, TypeDefinition, TypedAstToken}, | ||
utils::token::to_ident_key, | ||
}; | ||
use sway_core::{ | ||
declaration_engine as de, | ||
language::{ | ||
parsed::{AstNode, AstNodeContent, Declaration}, | ||
ty, | ||
}, | ||
}; | ||
use sway_types::Spanned; | ||
|
||
/// Insert Declaration tokens into the TokenMap. | ||
pub fn collect_parsed_declaration(node: &AstNode, tokens: &TokenMap) { | ||
if let AstNodeContent::Declaration(declaration) = &node.content { | ||
let parsed_token = AstToken::Declaration(declaration.clone()); | ||
|
||
let (ident, symbol_kind) = match declaration { | ||
Declaration::VariableDeclaration(variable) => { | ||
(variable.name.clone(), SymbolKind::Variable) | ||
} | ||
Declaration::StructDeclaration(decl) => (decl.name.clone(), SymbolKind::Struct), | ||
Declaration::TraitDeclaration(decl) => (decl.name.clone(), SymbolKind::Trait), | ||
Declaration::FunctionDeclaration(decl) => (decl.name.clone(), SymbolKind::Function), | ||
Declaration::ConstantDeclaration(decl) => (decl.name.clone(), SymbolKind::Const), | ||
Declaration::EnumDeclaration(decl) => (decl.name.clone(), SymbolKind::Enum), | ||
_ => return, | ||
}; | ||
|
||
let key = to_ident_key(&ident); | ||
let token = Token::from_parsed(parsed_token, symbol_kind); | ||
tokens.insert(key, token); | ||
} | ||
} | ||
|
||
/// Insert TypedDeclaration tokens into the TokenMap. | ||
pub fn collect_typed_declaration(node: &ty::TyAstNode, tokens: &TokenMap) { | ||
if let ty::TyAstNodeContent::Declaration(declaration) = &node.content { | ||
let typed_token = TypedAstToken::TypedDeclaration(declaration.clone()); | ||
|
||
if let Ok(ident) = match declaration { | ||
ty::TyDeclaration::VariableDeclaration(variable) => Ok(variable.name.clone()), | ||
ty::TyDeclaration::StructDeclaration(decl_id) => { | ||
de::de_get_struct(decl_id.clone(), &declaration.span()).map(|decl| decl.name) | ||
} | ||
ty::TyDeclaration::TraitDeclaration(decl_id) => { | ||
de::de_get_trait(decl_id.clone(), &declaration.span()).map(|decl| decl.name) | ||
} | ||
ty::TyDeclaration::FunctionDeclaration(decl_id) => { | ||
de::de_get_function(decl_id.clone(), &declaration.span()).map(|decl| decl.name) | ||
} | ||
ty::TyDeclaration::ConstantDeclaration(decl_id) => { | ||
de::de_get_constant(decl_id.clone(), &declaration.span()).map(|decl| decl.name) | ||
} | ||
ty::TyDeclaration::EnumDeclaration(decl_id) => { | ||
de::de_get_enum(decl_id.clone(), &declaration.span()).map(|decl| decl.name) | ||
} | ||
_ => return, | ||
} { | ||
let ident = to_ident_key(&ident); | ||
if let Some(mut token) = tokens.get_mut(&ident) { | ||
token.typed = Some(typed_token); | ||
token.type_def = Some(TypeDefinition::Ident(ident.0)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub(crate) mod config; | ||
pub(crate) mod dependency; | ||
pub mod document; | ||
pub mod session; | ||
pub(crate) mod token; | ||
|
Oops, something went wrong.