Formatting and docs

This commit is contained in:
John Renner 2021-05-10 13:34:09 -07:00
parent c3ba1f14fa
commit 7ae3967e57
6 changed files with 35 additions and 16 deletions

View file

@ -44,9 +44,6 @@ struct ConfigData {
/// Show function name and docs in parameter hints.
callInfo_full: bool = "true",
/// Use semantic tokens for strings. Disable to support injected grammars
semanticStringTokens: bool = "true",
/// Automatically refresh project info via `cargo metadata` on
/// `Cargo.toml` changes.
cargo_autoreload: bool = "true",
@ -211,6 +208,13 @@ struct ConfigData {
/// Advanced option, fully override the command rust-analyzer uses for
/// formatting.
rustfmt_overrideCommand: Option<Vec<String>> = "null",
/// Use semantic tokens for strings.
///
/// In some editors (e.g. vscode) semantic tokens override other highlighting grammars.
/// By disabling semantic tokens for strings, other grammars can be used to highlight
/// their contents.
semanticStringTokens: bool = "true",
}
}

View file

@ -1377,7 +1377,8 @@ pub(crate) fn handle_semantic_tokens_full(
let highlights = snap.analysis.highlight(file_id)?;
let semantic_strings = snap.config.semantic_strings();
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings);
let semantic_tokens =
to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings);
// Unconditionally cache the tokens
snap.semantic_tokens_cache.lock().insert(params.text_document.uri, semantic_tokens.clone());
@ -1397,7 +1398,8 @@ pub(crate) fn handle_semantic_tokens_full_delta(
let highlights = snap.analysis.highlight(file_id)?;
let semantic_strings = snap.config.semantic_strings();
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings);
let semantic_tokens =
to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings);
let mut cache = snap.semantic_tokens_cache.lock();
let cached_tokens = cache.entry(params.text_document.uri).or_default();
@ -1427,7 +1429,8 @@ pub(crate) fn handle_semantic_tokens_range(
let highlights = snap.analysis.highlight_range(frange)?;
let semantic_strings = snap.config.semantic_strings();
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings);
let semantic_tokens =
to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings);
Ok(Some(semantic_tokens.into()))
}

View file

@ -381,7 +381,7 @@ pub(crate) fn semantic_tokens(
text: &str,
line_index: &LineIndex,
highlights: Vec<HlRange>,
include_strings: bool
include_strings: bool,
) -> lsp_types::SemanticTokens {
let id = TOKEN_RESULT_COUNTER.fetch_add(1, Ordering::SeqCst).to_string();
let mut builder = semantic_tokens::SemanticTokensBuilder::new(id);

View file

@ -18,13 +18,13 @@
notification::DidOpenTextDocument,
request::{
CodeActionRequest, Completion, Formatting, GotoTypeDefinition, HoverRequest,
SemanticTokensRangeRequest, WillRenameFiles
SemanticTokensRangeRequest, WillRenameFiles,
},
CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams,
DocumentFormattingParams, FileRename, FormattingOptions, GotoDefinitionParams, HoverParams,
PartialResultParams, Position, Range, RenameFilesParams, SemanticTokensRangeParams, TextDocumentItem,
TextDocumentPositionParams, WorkDoneProgressParams,
SemanticTokens
PartialResultParams, Position, Range, RenameFilesParams, SemanticTokens,
SemanticTokensRangeParams, TextDocumentItem, TextDocumentPositionParams,
WorkDoneProgressParams,
};
use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams};
use serde_json::{from_value, json};
@ -56,10 +56,9 @@ fn can_disable_semantic_strings() {
const foo: &'static str = "hi";
"#,
)
.with_config(serde_json::json!({
"semanticStringTokens": semantic_strings
}))
.server().wait_until_workspace_is_loaded();
.with_config(serde_json::json!({ "semanticStringTokens": semantic_strings }))
.server()
.wait_until_workspace_is_loaded();
let res = server.send_request::<SemanticTokensRangeRequest>(SemanticTokensRangeParams {
text_document: server.doc_id("src/lib.rs"),
@ -73,7 +72,6 @@ fn can_disable_semantic_strings() {
});
}
#[test]
fn completes_items_from_standard_library() {
if skip_slow_tests() {

View file

@ -332,3 +332,12 @@ Additional arguments to `rustfmt`.
Advanced option, fully override the command rust-analyzer uses for
formatting.
--
[[rust-analyzer.semanticStringTokens]]rust-analyzer.semanticStringTokens (default: `true`)::
+
--
Use semantic tokens for strings.
In some editors (e.g. vscode) semantic tokens override other highlighting grammars.
By disabling semantic tokens for strings, other grammars can be used to highlight
their contents.
--

View file

@ -770,6 +770,11 @@
"type": "string"
}
},
"rust-analyzer.semanticStringTokens": {
"markdownDescription": "Use semantic tokens for strings.\n\nIn some editors (e.g. vscode) semantic tokens override other highlighting grammars.\nBy disabling semantic tokens for strings, other grammars can be used to highlight\ntheir contents.",
"default": true,
"type": "boolean"
},
"$generated-end": false
}
},