2021-01-11 12:13:41 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2020-12-07 05:46:39 -05:00
|
|
|
|
|
|
|
///!
|
|
|
|
///! Provides information about what capabilities that are supported by the
|
|
|
|
///! language server, which helps determine what messages are sent from the
|
|
|
|
///! client.
|
|
|
|
///!
|
2021-04-19 01:11:26 -04:00
|
|
|
use lspower::lsp::CallHierarchyServerCapability;
|
2021-01-29 14:34:33 -05:00
|
|
|
use lspower::lsp::ClientCapabilities;
|
2021-02-04 13:53:02 -05:00
|
|
|
use lspower::lsp::CodeActionKind;
|
|
|
|
use lspower::lsp::CodeActionOptions;
|
|
|
|
use lspower::lsp::CodeActionProviderCapability;
|
2021-01-31 22:30:41 -05:00
|
|
|
use lspower::lsp::CodeLensOptions;
|
2021-01-29 14:34:33 -05:00
|
|
|
use lspower::lsp::CompletionOptions;
|
2021-11-22 19:08:56 -05:00
|
|
|
use lspower::lsp::DocumentSymbolOptions;
|
2021-04-02 02:21:07 -04:00
|
|
|
use lspower::lsp::FoldingRangeProviderCapability;
|
2021-01-29 14:34:33 -05:00
|
|
|
use lspower::lsp::HoverProviderCapability;
|
|
|
|
use lspower::lsp::ImplementationProviderCapability;
|
|
|
|
use lspower::lsp::OneOf;
|
|
|
|
use lspower::lsp::SaveOptions;
|
2021-03-23 19:33:25 -04:00
|
|
|
use lspower::lsp::SelectionRangeProviderCapability;
|
2021-04-19 21:26:36 -04:00
|
|
|
use lspower::lsp::SemanticTokensFullOptions;
|
|
|
|
use lspower::lsp::SemanticTokensOptions;
|
|
|
|
use lspower::lsp::SemanticTokensServerCapabilities;
|
2021-01-29 14:34:33 -05:00
|
|
|
use lspower::lsp::ServerCapabilities;
|
2021-02-15 21:34:09 -05:00
|
|
|
use lspower::lsp::SignatureHelpOptions;
|
2021-01-29 14:34:33 -05:00
|
|
|
use lspower::lsp::TextDocumentSyncCapability;
|
|
|
|
use lspower::lsp::TextDocumentSyncKind;
|
|
|
|
use lspower::lsp::TextDocumentSyncOptions;
|
2021-11-22 19:09:19 -05:00
|
|
|
use lspower::lsp::TypeDefinitionProviderCapability;
|
2021-01-29 14:34:33 -05:00
|
|
|
use lspower::lsp::WorkDoneProgressOptions;
|
2021-05-09 21:16:04 -04:00
|
|
|
use lspower::lsp::WorkspaceFoldersServerCapabilities;
|
|
|
|
use lspower::lsp::WorkspaceServerCapabilities;
|
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())
|
|
|
|
.map_or(CodeActionProviderCapability::Simple(true), |_| {
|
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(),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-12-07 05:46:39 -05:00
|
|
|
pub fn server_capabilities(
|
2021-02-04 13:53:02 -05:00
|
|
|
client_capabilities: &ClientCapabilities,
|
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),
|
|
|
|
change: Some(TextDocumentSyncKind::Incremental),
|
|
|
|
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 {
|
2021-03-15 18:01:41 -04:00
|
|
|
all_commit_characters: Some(vec![
|
|
|
|
".".to_string(),
|
|
|
|
",".to_string(),
|
|
|
|
";".to_string(),
|
|
|
|
"(".to_string(),
|
|
|
|
]),
|
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,
|
|
|
|
execute_command_provider: None,
|
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),
|
|
|
|
change_notifications: None,
|
|
|
|
}),
|
|
|
|
file_operations: None,
|
|
|
|
}),
|
2020-12-07 05:46:39 -05:00
|
|
|
experimental: None,
|
2021-01-12 02:50:02 -05:00
|
|
|
linked_editing_range_provider: None,
|
|
|
|
moniker_provider: None,
|
2020-12-07 05:46:39 -05:00
|
|
|
}
|
|
|
|
}
|