1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! The active editor's language and whether its server supports a feature (declaration,
//! type definition, implementations, references, call hierarchy, code actions): the gates
//! on the right-click menu's rows.
use super::*;
impl App {
/// Whether the current file's language server implements call hierarchy;
/// drives the right-click menu rows, like the other capability gates.
pub(in crate::app) fn editor_language_supports_call_hierarchy(&self) -> bool {
self.editor_language_supports(crate::lsp::LspManager::language_supports_call_hierarchy)
}
/// The language the current editor file's name or extension maps to, if
/// any.
pub(in crate::app) fn editor_language(&self) -> Option<crate::lsp::Language> {
self.editor
.path
.as_deref()
.and_then(crate::lsp::Language::from_path)
}
/// Whether the current editor file's language server reports support
/// through `supports`, one of the `language_supports_*` getters on
/// [`crate::lsp::LspManager`]. Unknown (server not yet spawned) or no
/// server counts as unsupported, so a gated row only appears once support
/// is confirmed.
pub(in crate::app) fn editor_language_supports(
&self,
supports: fn(&crate::lsp::LspManager, crate::lsp::Language) -> Option<bool>,
) -> bool {
let Some(lang) = self.editor_language() else {
return false;
};
self.lsp
.manager
.as_ref()
.and_then(|lsp| supports(lsp, lang))
.unwrap_or(false)
}
}
impl App {
/// Whether the current editor file's language server implements
/// `textDocument/declaration`. Drives whether the right-click menu shows the
/// "Go to Declaration" row. Unknown (server not yet spawned) or no server is
/// treated as unsupported, so the row only appears once support is confirmed.
pub(in crate::app) fn editor_language_supports_declaration(&self) -> bool {
self.editor_language_supports(crate::lsp::LspManager::language_supports_declaration)
}
/// Whether the current editor file's language server implements
/// `textDocument/typeDefinition`. Drives whether the right-click menu shows
/// the "Go to Type Definition" row. Unknown (server not yet spawned) or no
/// server is treated as unsupported, so the row only appears once support is
/// confirmed.
pub(in crate::app) fn editor_language_supports_type_definition(&self) -> bool {
self.editor_language_supports(crate::lsp::LspManager::language_supports_type_definition)
}
/// Whether the current editor file's language server implements
/// `textDocument/implementation`. Drives whether the right-click menu shows
/// the "Go to Implementations" row. Unknown (server not yet spawned) or no
/// server is treated as unsupported, so the row only appears once support is
/// confirmed.
pub(in crate::app) fn editor_language_supports_implementation(&self) -> bool {
self.editor_language_supports(crate::lsp::LspManager::language_supports_implementation)
}
/// Whether the current editor file's language server implements
/// `textDocument/references`. Drives whether the right-click menu shows the
/// "Go to References" row. Unknown (server not yet spawned) or no server is
/// treated as unsupported, so the row only appears once support is confirmed.
pub(in crate::app) fn editor_language_supports_references(&self) -> bool {
self.editor_language_supports(crate::lsp::LspManager::language_supports_references)
}
pub(in crate::app) fn editor_language_supports_code_action(&self) -> bool {
self.editor_language_supports(crate::lsp::LspManager::language_supports_code_action)
}
}