mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-07-07 21:25:32 +00:00
Only return LoationLink if the client supports it (#1411)
This commit is contained in:
parent
b8c332c75b
commit
28e952339f
5 changed files with 38 additions and 9 deletions
|
@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Regenerate diagnostics after loading the TeX distribution ([#1376](https://github.com/latex-lsp/texlab/issues/1376))
|
||||
- Improve handling of nested curly braces in command parsing ([#1360](https://github.com/latex-lsp/texlab/issues/1360))
|
||||
- Don't panic if the server receives a completion request with an invalid position ([#1367](https://github.com/latex-lsp/texlab/pull/1367))
|
||||
- Only return `LocationLink[]` in `textDocument/definition` if the client supports it ([#1399](https://github.com/latex-lsp/texlab/issues/1399))
|
||||
|
||||
## [5.22.1] - 2025-01-29
|
||||
|
||||
|
|
|
@ -1,16 +1,31 @@
|
|||
use base_db::Workspace;
|
||||
use base_db::{DocumentLocation, Workspace};
|
||||
|
||||
use crate::util::{from_proto, to_proto};
|
||||
use crate::util::{from_proto, to_proto, ClientFlags};
|
||||
|
||||
pub fn goto_definition(
|
||||
workspace: &Workspace,
|
||||
params: lsp_types::GotoDefinitionParams,
|
||||
client_flags: &ClientFlags,
|
||||
) -> Option<lsp_types::GotoDefinitionResponse> {
|
||||
let params = from_proto::definition_params(workspace, params)?;
|
||||
let links = definition::goto_definition(¶ms)
|
||||
.into_iter()
|
||||
.filter_map(|result| to_proto::location_link(result, ¶ms.feature.document.line_index))
|
||||
.collect();
|
||||
let results = definition::goto_definition(¶ms);
|
||||
|
||||
Some(lsp_types::GotoDefinitionResponse::Link(links))
|
||||
if client_flags.location_link_support {
|
||||
let links = results
|
||||
.into_iter()
|
||||
.filter_map(|result| {
|
||||
to_proto::location_link(result, ¶ms.feature.document.line_index)
|
||||
})
|
||||
.collect();
|
||||
|
||||
Some(lsp_types::GotoDefinitionResponse::Link(links))
|
||||
} else {
|
||||
let locations = results
|
||||
.into_iter()
|
||||
.map(|result| DocumentLocation::new(result.target, result.target_range))
|
||||
.filter_map(to_proto::location)
|
||||
.collect();
|
||||
|
||||
Some(lsp_types::GotoDefinitionResponse::Array(locations))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -563,7 +563,10 @@ impl Server {
|
|||
|
||||
fn goto_definition(&self, id: RequestId, mut params: GotoDefinitionParams) -> Result<()> {
|
||||
normalize_uri(&mut params.text_document_position_params.text_document.uri);
|
||||
self.run_query(id, move |db| definition::goto_definition(db, params));
|
||||
let client_flags = Arc::clone(&self.client_flags);
|
||||
self.run_query(id, move |db| {
|
||||
definition::goto_definition(db, params, &client_flags)
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1117,7 +1120,6 @@ impl Server {
|
|||
let client = self.client.clone();
|
||||
|
||||
self.pool.execute(move || {
|
||||
|
||||
let progress_reporter = if progress {
|
||||
let token = NEXT_TOKEN.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||
Some(ProgressReporter::new_inputs_progress(client.clone(), token))
|
||||
|
|
|
@ -38,4 +38,7 @@ pub struct ClientFlags {
|
|||
|
||||
/// If `true`, the server can let the client open a document using `window/showDocument`.
|
||||
pub show_document: bool,
|
||||
|
||||
/// If `true`, the server can return `LocationLink` instead of `Location`.
|
||||
pub location_link_support: bool,
|
||||
}
|
||||
|
|
|
@ -102,6 +102,13 @@ pub fn client_flags(
|
|||
.and_then(|cap| cap.show_document.as_ref())
|
||||
.map_or(false, |cap| cap.support);
|
||||
|
||||
let location_link_support = capabilities
|
||||
.text_document
|
||||
.as_ref()
|
||||
.and_then(|cap| cap.definition.as_ref())
|
||||
.and_then(|cap| cap.link_support)
|
||||
.unwrap_or(false);
|
||||
|
||||
ClientFlags {
|
||||
hierarchical_document_symbols,
|
||||
completion_markdown,
|
||||
|
@ -114,6 +121,7 @@ pub fn client_flags(
|
|||
folding_custom_kinds,
|
||||
progress,
|
||||
show_document,
|
||||
location_link_support,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue