2019-12-21 15:27:38 -05:00
|
|
|
//! Advertizes the capabilities of the LSP Server.
|
2020-05-03 20:56:36 +03:00
|
|
|
use std::env;
|
2019-09-30 11:58:53 +03:00
|
|
|
|
2019-01-14 13:55:56 +03:00
|
|
|
use lsp_types::{
|
2020-07-11 17:29:45 -04:00
|
|
|
CallHierarchyServerCapability, ClientCapabilities, CodeActionKind, CodeActionOptions,
|
2020-05-19 11:56:51 -04:00
|
|
|
CodeActionProviderCapability, CodeLensOptions, CompletionOptions,
|
|
|
|
DocumentOnTypeFormattingOptions, FoldingRangeProviderCapability,
|
|
|
|
ImplementationProviderCapability, RenameOptions, RenameProviderCapability, SaveOptions,
|
|
|
|
SelectionRangeProviderCapability, SemanticTokensDocumentProvider, SemanticTokensLegend,
|
|
|
|
SemanticTokensOptions, ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability,
|
|
|
|
TextDocumentSyncKind, TextDocumentSyncOptions, TypeDefinitionProviderCapability,
|
|
|
|
WorkDoneProgressOptions,
|
2018-08-10 21:13:39 +03:00
|
|
|
};
|
2020-05-21 19:50:23 +02:00
|
|
|
use serde_json::json;
|
|
|
|
|
|
|
|
use crate::semantic_tokens;
|
2018-08-10 15:07:43 +03:00
|
|
|
|
2020-05-19 11:56:51 -04:00
|
|
|
pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabilities {
|
2020-05-19 17:22:38 -04:00
|
|
|
let code_action_provider = code_action_capabilities(client_caps);
|
2020-05-19 11:56:51 -04:00
|
|
|
|
2018-08-13 02:38:34 +03:00
|
|
|
ServerCapabilities {
|
2019-02-08 14:49:43 +03:00
|
|
|
text_document_sync: Some(TextDocumentSyncCapability::Options(TextDocumentSyncOptions {
|
|
|
|
open_close: Some(true),
|
2020-05-04 19:54:23 +03:00
|
|
|
change: Some(if env::var("RA_NO_INCREMENTAL_SYNC").is_ok() {
|
2020-05-03 20:56:36 +03:00
|
|
|
TextDocumentSyncKind::Full
|
2020-05-04 19:54:23 +03:00
|
|
|
} else {
|
|
|
|
TextDocumentSyncKind::Incremental
|
2020-05-03 20:56:36 +03:00
|
|
|
}),
|
2019-02-08 14:49:43 +03:00
|
|
|
will_save: None,
|
|
|
|
will_save_wait_until: None,
|
2019-12-25 12:21:38 +01:00
|
|
|
save: Some(SaveOptions::default()),
|
2019-02-08 14:49:43 +03:00
|
|
|
})),
|
2018-11-05 16:37:27 -05:00
|
|
|
hover_provider: Some(true),
|
2018-08-26 12:51:45 +03:00
|
|
|
completion_provider: Some(CompletionOptions {
|
|
|
|
resolve_provider: None,
|
2018-12-25 15:20:37 +01:00
|
|
|
trigger_characters: Some(vec![":".to_string(), ".".to_string()]),
|
2019-12-11 18:34:01 +01:00
|
|
|
work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
|
2018-08-26 12:51:45 +03:00
|
|
|
}),
|
2018-10-09 10:08:17 -04:00
|
|
|
signature_help_provider: Some(SignatureHelpOptions {
|
2019-12-12 07:55:05 -05:00
|
|
|
trigger_characters: Some(vec!["(".to_string(), ",".to_string()]),
|
2019-12-11 18:34:01 +01:00
|
|
|
retrigger_characters: None,
|
|
|
|
work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
|
2018-10-09 10:08:17 -04:00
|
|
|
}),
|
2019-12-11 18:34:01 +01:00
|
|
|
declaration_provider: None,
|
2018-08-13 16:35:17 +03:00
|
|
|
definition_provider: Some(true),
|
2019-04-23 14:11:27 -04:00
|
|
|
type_definition_provider: Some(TypeDefinitionProviderCapability::Simple(true)),
|
2019-01-28 09:26:32 -05:00
|
|
|
implementation_provider: Some(ImplementationProviderCapability::Simple(true)),
|
2018-10-18 13:40:12 -04:00
|
|
|
references_provider: Some(true),
|
2018-12-31 11:08:44 +00:00
|
|
|
document_highlight_provider: Some(true),
|
2018-08-13 02:38:34 +03:00
|
|
|
document_symbol_provider: Some(true),
|
2018-08-13 15:35:53 +03:00
|
|
|
workspace_symbol_provider: Some(true),
|
2020-05-19 11:56:51 -04:00
|
|
|
code_action_provider: Some(code_action_provider),
|
2019-02-08 14:49:43 +03:00
|
|
|
code_lens_provider: Some(CodeLensOptions { resolve_provider: Some(true) }),
|
2018-12-29 20:09:42 +01:00
|
|
|
document_formatting_provider: Some(true),
|
2018-08-13 02:38:34 +03:00
|
|
|
document_range_formatting_provider: None,
|
2018-08-28 11:12:42 +03:00
|
|
|
document_on_type_formatting_provider: Some(DocumentOnTypeFormattingOptions {
|
|
|
|
first_trigger_character: "=".to_string(),
|
2019-10-25 12:16:56 +03:00
|
|
|
more_trigger_character: Some(vec![".".to_string(), ">".to_string()]),
|
2018-08-28 11:12:42 +03:00
|
|
|
}),
|
2019-12-20 18:57:31 -05:00
|
|
|
selection_range_provider: Some(SelectionRangeProviderCapability::Simple(true)),
|
2019-12-23 09:33:49 -05:00
|
|
|
semantic_highlighting: None,
|
2018-09-23 11:10:57 -04:00
|
|
|
folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)),
|
2018-10-31 23:41:43 +03:00
|
|
|
rename_provider: Some(RenameProviderCapability::Options(RenameOptions {
|
|
|
|
prepare_provider: Some(true),
|
2019-12-11 18:34:01 +01:00
|
|
|
work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
|
2018-10-18 17:56:22 -04:00
|
|
|
})),
|
2019-09-03 10:50:39 -04:00
|
|
|
document_link_provider: None,
|
2018-08-13 02:38:34 +03:00
|
|
|
color_provider: None,
|
2019-07-10 22:49:29 -07:00
|
|
|
execute_command_provider: None,
|
2018-09-23 11:10:57 -04:00
|
|
|
workspace: None,
|
2019-12-30 09:12:06 -05:00
|
|
|
call_hierarchy_provider: Some(CallHierarchyServerCapability::Simple(true)),
|
2020-02-25 08:38:50 -05:00
|
|
|
semantic_tokens_provider: Some(
|
2020-02-14 17:56:28 -05:00
|
|
|
SemanticTokensOptions {
|
|
|
|
legend: SemanticTokensLegend {
|
2020-03-02 14:05:44 -05:00
|
|
|
token_types: semantic_tokens::SUPPORTED_TYPES.to_vec(),
|
|
|
|
token_modifiers: semantic_tokens::SUPPORTED_MODIFIERS.to_vec(),
|
2020-02-14 17:56:28 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
document_provider: Some(SemanticTokensDocumentProvider::Bool(true)),
|
2020-02-25 08:38:50 -05:00
|
|
|
range_provider: Some(true),
|
|
|
|
work_done_progress_options: Default::default(),
|
|
|
|
}
|
|
|
|
.into(),
|
|
|
|
),
|
2020-05-21 19:50:23 +02:00
|
|
|
experimental: Some(json!({
|
|
|
|
"joinLines": true,
|
2020-05-22 00:28:49 +02:00
|
|
|
"ssr": true,
|
2020-05-25 14:12:53 +02:00
|
|
|
"onEnter": true,
|
2020-05-25 15:55:25 +02:00
|
|
|
"parentModule": true,
|
2020-06-02 17:34:18 +02:00
|
|
|
"runnables": {
|
|
|
|
"kinds": [ "cargo" ],
|
|
|
|
},
|
2020-05-21 19:50:23 +02:00
|
|
|
})),
|
2018-08-13 02:38:34 +03:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 17:22:38 -04:00
|
|
|
|
|
|
|
fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProviderCapability {
|
|
|
|
client_caps
|
|
|
|
.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), |_| {
|
|
|
|
CodeActionProviderCapability::Options(CodeActionOptions {
|
|
|
|
// Advertise support for all built-in CodeActionKinds.
|
|
|
|
// Ideally we would base this off of the client capabilities
|
|
|
|
// but the client is supposed to fall back gracefully for unknown values.
|
|
|
|
code_action_kinds: Some(vec![
|
2020-07-11 17:29:45 -04:00
|
|
|
CodeActionKind::EMPTY,
|
|
|
|
CodeActionKind::QUICKFIX,
|
|
|
|
CodeActionKind::REFACTOR,
|
|
|
|
CodeActionKind::REFACTOR_EXTRACT,
|
|
|
|
CodeActionKind::REFACTOR_INLINE,
|
|
|
|
CodeActionKind::REFACTOR_REWRITE,
|
2020-05-19 17:22:38 -04:00
|
|
|
]),
|
|
|
|
work_done_progress_options: Default::default(),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|