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>,
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SemanticToken {
|
pub struct SemanticToken {
|
||||||
pub ty: Option<TypeKind>,
|
pub ty: Option<TypeKind>,
|
||||||
|
@ -263,32 +263,20 @@ impl LanguageServer for Backend {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if let Some(token) = token {
|
if let Some(token) = token {
|
||||||
dbg!(token);
|
if let Some(def_token) = analysis.find_definition(token.0) {
|
||||||
if let Some(semantic_token) = analysis.state.map.get(&token.0) {
|
return Ok(Some(GotoDefinitionResponse::Scalar(lsp_types::Location {
|
||||||
dbg!(semantic_token);
|
uri: params.text_document_position_params.text_document.uri,
|
||||||
if let Some(symbol_id) = semantic_token.symbol {
|
range: Range {
|
||||||
dbg!(symbol_id);
|
start: lsp_types::Position {
|
||||||
let definition_id = analysis.state.find_definition(&symbol_id);
|
line: def_token.position.1.max(1) - 1,
|
||||||
if let Some(def_token_idx) = analysis.state.symbol_to_token.get(&definition_id) {
|
character: def_token.position.0.max(1) - 1,
|
||||||
dbg!(def_token_idx);
|
},
|
||||||
if let Some(def_token) = analysis.tokens.get(*def_token_idx) {
|
end: lsp_types::Position {
|
||||||
dbg!(def_token);
|
line: def_token.position.1.max(1) - 1,
|
||||||
return Ok(Some(GotoDefinitionResponse::Scalar(lsp_types::Location {
|
character: def_token.position.0.max(1) - 1 + def_token.token.len() as u32,
|
||||||
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