Flatten a pyramid with a helper function
This commit is contained in:
parent
ac0d79f816
commit
0abeb0c4cd
@ -44,6 +44,17 @@ pub struct StaticAnalysis {
|
||||
pub error: Option<ReidError>,
|
||||
}
|
||||
|
||||
impl StaticAnalysis {
|
||||
pub fn find_definition(&self, token_idx: usize) -> Option<&FullToken> {
|
||||
let semantic_token = self.state.map.get(&token_idx)?;
|
||||
let symbol_id = semantic_token.symbol?;
|
||||
let definition_id = self.state.find_definition(&symbol_id);
|
||||
|
||||
let def_token_idx = self.state.symbol_to_token.get(&definition_id)?;
|
||||
self.tokens.get(*def_token_idx)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SemanticToken {
|
||||
pub ty: Option<TypeKind>,
|
||||
|
@ -263,32 +263,20 @@ impl LanguageServer for Backend {
|
||||
});
|
||||
|
||||
if let Some(token) = token {
|
||||
dbg!(token);
|
||||
if let Some(semantic_token) = analysis.state.map.get(&token.0) {
|
||||
dbg!(semantic_token);
|
||||
if let Some(symbol_id) = semantic_token.symbol {
|
||||
dbg!(symbol_id);
|
||||
let definition_id = analysis.state.find_definition(&symbol_id);
|
||||
if let Some(def_token_idx) = analysis.state.symbol_to_token.get(&definition_id) {
|
||||
dbg!(def_token_idx);
|
||||
if let Some(def_token) = analysis.tokens.get(*def_token_idx) {
|
||||
dbg!(def_token);
|
||||
return Ok(Some(GotoDefinitionResponse::Scalar(lsp_types::Location {
|
||||
uri: params.text_document_position_params.text_document.uri,
|
||||
range: Range {
|
||||
start: lsp_types::Position {
|
||||
line: def_token.position.1.max(1) - 1,
|
||||
character: def_token.position.0.max(1) - 1,
|
||||
},
|
||||
end: lsp_types::Position {
|
||||
line: def_token.position.1.max(1) - 1,
|
||||
character: def_token.position.0.max(1) - 1 + def_token.token.len() as u32,
|
||||
},
|
||||
},
|
||||
})));
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(def_token) = analysis.find_definition(token.0) {
|
||||
return Ok(Some(GotoDefinitionResponse::Scalar(lsp_types::Location {
|
||||
uri: params.text_document_position_params.text_document.uri,
|
||||
range: Range {
|
||||
start: lsp_types::Position {
|
||||
line: def_token.position.1.max(1) - 1,
|
||||
character: def_token.position.0.max(1) - 1,
|
||||
},
|
||||
end: lsp_types::Position {
|
||||
line: def_token.position.1.max(1) - 1,
|
||||
character: def_token.position.0.max(1) - 1 + def_token.token.len() as u32,
|
||||
},
|
||||
},
|
||||
})));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user