2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2020-12-07 05:46:39 -05:00
|
|
|
|
2023-06-05 20:35:39 -04:00
|
|
|
//!
|
|
|
|
//! Provides information about what capabilities that are supported by the
|
|
|
|
//! language server, which helps determine what messages are sent from the
|
|
|
|
//! client.
|
|
|
|
//!
|
2022-03-28 20:27:43 -04:00
|
|
|
use deno_core::serde_json::json;
|
2022-04-03 00:17:30 -04:00
|
|
|
use tower_lsp::lsp_types::*;
|
2020-12-07 05:46:39 -05:00
|
|
|
|
2021-08-05 21:46:32 -04:00
|
|
|
use super::refactor::ALL_KNOWN_REFACTOR_ACTION_KINDS;
|
2021-04-19 21:26:36 -04:00
|
|
|
use super::semantic_tokens::get_legend;
|
|
|
|
|
2021-02-04 13:53:02 -05:00
|
|
|
fn code_action_capabilities(
|
|
|
|
client_capabilities: &ClientCapabilities,
|
|
|
|
) -> CodeActionProviderCapability {
|
|
|
|
client_capabilities
|
|
|
|
.text_document
|
|
|
|
.as_ref()
|
|
|
|
.and_then(|it| it.code_action.as_ref())
|
|
|
|
.and_then(|it| it.code_action_literal_support.as_ref())
|
2023-03-15 17:46:36 -04:00
|
|
|
.map(|_| {
|
2021-08-05 21:46:32 -04:00
|
|
|
let mut code_action_kinds =
|
|
|
|
vec![CodeActionKind::QUICKFIX, CodeActionKind::REFACTOR];
|
|
|
|
code_action_kinds.extend(
|
|
|
|
ALL_KNOWN_REFACTOR_ACTION_KINDS
|
|
|
|
.iter()
|
|
|
|
.map(|action| action.kind.clone()),
|
|
|
|
);
|
|
|
|
|
2021-02-04 13:53:02 -05:00
|
|
|
CodeActionProviderCapability::Options(CodeActionOptions {
|
2021-08-05 21:46:32 -04:00
|
|
|
code_action_kinds: Some(code_action_kinds),
|
2021-02-05 15:10:53 -05:00
|
|
|
resolve_provider: Some(true),
|
2021-02-04 13:53:02 -05:00
|
|
|
work_done_progress_options: Default::default(),
|
|
|
|
})
|
|
|
|
})
|
2023-03-15 17:46:36 -04:00
|
|
|
.unwrap_or(CodeActionProviderCapability::Simple(true))
|
2021-02-04 13:53:02 -05:00
|
|
|
}
|
|
|
|
|
2020-12-07 05:46:39 -05:00
|
|
|
pub fn server_capabilities(
|
2021-02-04 13:53:02 -05:00
|
|
|
client_capabilities: &ClientCapabilities,
|
2023-09-05 11:36:35 -04:00
|
|
|
enable_builtin_commands: bool,
|
2020-12-07 05:46:39 -05:00
|
|
|
) -> ServerCapabilities {
|
2021-02-04 13:53:02 -05:00
|
|
|
let code_action_provider = code_action_capabilities(client_capabilities);
|
2020-12-07 05:46:39 -05:00
|
|
|
ServerCapabilities {
|
|
|
|
text_document_sync: Some(TextDocumentSyncCapability::Options(
|
|
|
|
TextDocumentSyncOptions {
|
|
|
|
open_close: Some(true),
|
2021-11-24 20:10:12 -05:00
|
|
|
change: Some(TextDocumentSyncKind::INCREMENTAL),
|
2020-12-07 05:46:39 -05:00
|
|
|
will_save: None,
|
|
|
|
will_save_wait_until: None,
|
|
|
|
save: Some(SaveOptions::default().into()),
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
hover_provider: Some(HoverProviderCapability::Simple(true)),
|
2020-12-08 05:36:13 -05:00
|
|
|
completion_provider: Some(CompletionOptions {
|
2023-08-28 11:07:22 -04:00
|
|
|
// Don't include "," here as it leads to confusing completion
|
|
|
|
// behavior with function arguments. See https://github.com/denoland/deno/issues/20160
|
2021-03-15 18:01:41 -04:00
|
|
|
all_commit_characters: Some(vec![
|
|
|
|
".".to_string(),
|
|
|
|
";".to_string(),
|
|
|
|
"(".to_string(),
|
|
|
|
]),
|
2022-10-14 08:04:38 -04:00
|
|
|
completion_item: None,
|
2020-12-08 05:36:13 -05:00
|
|
|
trigger_characters: Some(vec![
|
|
|
|
".".to_string(),
|
|
|
|
"\"".to_string(),
|
|
|
|
"'".to_string(),
|
|
|
|
"`".to_string(),
|
|
|
|
"/".to_string(),
|
|
|
|
"@".to_string(),
|
|
|
|
"<".to_string(),
|
|
|
|
"#".to_string(),
|
|
|
|
]),
|
2021-03-15 18:01:41 -04:00
|
|
|
resolve_provider: Some(true),
|
2020-12-08 05:36:13 -05:00
|
|
|
work_done_progress_options: WorkDoneProgressOptions {
|
|
|
|
work_done_progress: None,
|
|
|
|
},
|
|
|
|
}),
|
2021-02-15 21:34:09 -05:00
|
|
|
signature_help_provider: Some(SignatureHelpOptions {
|
|
|
|
trigger_characters: Some(vec![
|
|
|
|
",".to_string(),
|
|
|
|
"(".to_string(),
|
|
|
|
"<".to_string(),
|
|
|
|
]),
|
2021-03-15 18:01:41 -04:00
|
|
|
retrigger_characters: Some(vec![")".to_string()]),
|
2021-02-15 21:34:09 -05:00
|
|
|
work_done_progress_options: WorkDoneProgressOptions {
|
|
|
|
work_done_progress: None,
|
|
|
|
},
|
|
|
|
}),
|
2020-12-07 05:46:39 -05:00
|
|
|
declaration_provider: None,
|
|
|
|
definition_provider: Some(OneOf::Left(true)),
|
2021-11-22 19:09:19 -05:00
|
|
|
type_definition_provider: Some(TypeDefinitionProviderCapability::Simple(
|
|
|
|
true,
|
|
|
|
)),
|
2021-01-12 16:53:27 -05:00
|
|
|
implementation_provider: Some(ImplementationProviderCapability::Simple(
|
|
|
|
true,
|
|
|
|
)),
|
2020-12-07 05:46:39 -05:00
|
|
|
references_provider: Some(OneOf::Left(true)),
|
|
|
|
document_highlight_provider: Some(OneOf::Left(true)),
|
2021-11-22 19:08:56 -05:00
|
|
|
document_symbol_provider: Some(OneOf::Right(DocumentSymbolOptions {
|
|
|
|
label: Some("Deno".to_string()),
|
|
|
|
work_done_progress_options: WorkDoneProgressOptions {
|
|
|
|
work_done_progress: None,
|
|
|
|
},
|
|
|
|
})),
|
|
|
|
workspace_symbol_provider: Some(OneOf::Left(true)),
|
2021-02-04 13:53:02 -05:00
|
|
|
code_action_provider: Some(code_action_provider),
|
2021-01-31 22:30:41 -05:00
|
|
|
code_lens_provider: Some(CodeLensOptions {
|
|
|
|
resolve_provider: Some(true),
|
|
|
|
}),
|
2020-12-07 05:46:39 -05:00
|
|
|
document_formatting_provider: Some(OneOf::Left(true)),
|
|
|
|
document_range_formatting_provider: None,
|
|
|
|
document_on_type_formatting_provider: None,
|
2021-03-23 19:33:25 -04:00
|
|
|
selection_range_provider: Some(SelectionRangeProviderCapability::Simple(
|
|
|
|
true,
|
|
|
|
)),
|
2021-04-02 02:21:07 -04:00
|
|
|
folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)),
|
2020-12-29 19:58:20 -05:00
|
|
|
rename_provider: Some(OneOf::Left(true)),
|
2020-12-07 05:46:39 -05:00
|
|
|
document_link_provider: None,
|
|
|
|
color_provider: None,
|
2023-09-05 11:36:35 -04:00
|
|
|
execute_command_provider: Some(ExecuteCommandOptions {
|
|
|
|
commands: if enable_builtin_commands {
|
2023-10-10 00:53:41 -04:00
|
|
|
vec![
|
|
|
|
"deno.cache".to_string(),
|
|
|
|
"deno.reloadImportRegistries".to_string(),
|
|
|
|
]
|
2023-09-05 11:36:35 -04:00
|
|
|
} else {
|
|
|
|
vec![]
|
|
|
|
},
|
|
|
|
..Default::default()
|
|
|
|
}),
|
2021-04-19 01:11:26 -04:00
|
|
|
call_hierarchy_provider: Some(CallHierarchyServerCapability::Simple(true)),
|
2021-04-19 21:26:36 -04:00
|
|
|
semantic_tokens_provider: Some(
|
|
|
|
SemanticTokensServerCapabilities::SemanticTokensOptions(
|
|
|
|
SemanticTokensOptions {
|
|
|
|
legend: get_legend(),
|
|
|
|
range: Some(true),
|
|
|
|
full: Some(SemanticTokensFullOptions::Bool(true)),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2021-05-09 21:16:04 -04:00
|
|
|
workspace: Some(WorkspaceServerCapabilities {
|
|
|
|
workspace_folders: Some(WorkspaceFoldersServerCapabilities {
|
|
|
|
supported: Some(true),
|
2022-03-20 21:33:37 -04:00
|
|
|
change_notifications: Some(OneOf::Left(true)),
|
2021-05-09 21:16:04 -04:00
|
|
|
}),
|
|
|
|
file_operations: None,
|
|
|
|
}),
|
2021-01-12 02:50:02 -05:00
|
|
|
linked_editing_range_provider: None,
|
|
|
|
moniker_provider: None,
|
2022-03-28 20:27:43 -04:00
|
|
|
experimental: Some(json!({
|
|
|
|
"denoConfigTasks": true,
|
2022-03-29 18:59:27 -04:00
|
|
|
"testingApi":true,
|
2022-03-28 20:27:43 -04:00
|
|
|
})),
|
2022-10-15 22:39:43 -04:00
|
|
|
inlay_hint_provider: Some(OneOf::Left(true)),
|
2022-10-27 13:34:44 -04:00
|
|
|
position_encoding: None,
|
2023-09-26 16:57:14 -04:00
|
|
|
// TODO(nayeemrmn): Support pull-based diagnostics.
|
|
|
|
diagnostic_provider: None,
|
|
|
|
inline_value_provider: None,
|
2020-12-07 05:46:39 -05:00
|
|
|
}
|
|
|
|
}
|