aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-02 11:47:58 +0100
committerAleksey Kladov <[email protected]>2020-04-02 11:47:58 +0100
commit48c58309cca718701e902b05221a8e8ec81310db (patch)
tree9f85d9bfb277ca780c2069757a6c11ab6de2229f
parente4cf40a152120c6c3cba1822e56026ae04be63f0 (diff)
Lean onto default implementation of configs
-rw-r--r--crates/rust-analyzer/src/config.rs6
-rw-r--r--crates/rust-analyzer/src/main_loop.rs17
-rw-r--r--crates/rust-analyzer/src/req.rs4
-rw-r--r--editors/code/package.json6
-rw-r--r--editors/code/src/client.ts26
-rw-r--r--editors/code/src/config.ts30
-rw-r--r--editors/code/src/ctx.ts3
-rw-r--r--editors/code/src/status_display.ts2
8 files changed, 24 insertions, 70 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index b19421c16..15aab7f09 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -38,12 +38,12 @@ pub struct Config {
38 38
39#[derive(Debug, Clone)] 39#[derive(Debug, Clone)]
40pub struct FilesConfig { 40pub struct FilesConfig {
41 watcher: FilesWatcher, 41 pub watcher: FilesWatcher,
42 exclude: Vec<String>, 42 pub exclude: Vec<String>,
43} 43}
44 44
45#[derive(Debug, Clone)] 45#[derive(Debug, Clone)]
46enum FilesWatcher { 46pub enum FilesWatcher {
47 Client, 47 Client,
48 Notify, 48 Notify,
49} 49}
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 47fef59d4..36ea85cc6 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -30,7 +30,7 @@ use serde::{de::DeserializeOwned, Serialize};
30use threadpool::ThreadPool; 30use threadpool::ThreadPool;
31 31
32use crate::{ 32use crate::{
33 config::Config, 33 config::{Config, FilesWatcher},
34 diagnostics::DiagnosticTask, 34 diagnostics::DiagnosticTask,
35 main_loop::{ 35 main_loop::{
36 pending_requests::{PendingRequest, PendingRequests}, 36 pending_requests::{PendingRequest, PendingRequests},
@@ -40,7 +40,6 @@ use crate::{
40 world::{WorldSnapshot, WorldState}, 40 world::{WorldSnapshot, WorldState},
41 Result, 41 Result,
42}; 42};
43use req::ConfigurationParams;
44 43
45#[derive(Debug)] 44#[derive(Debug)]
46pub struct LspError { 45pub struct LspError {
@@ -122,12 +121,13 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
122 }; 121 };
123 122
124 let globs = config 123 let globs = config
125 .exclude_globs 124 .files
125 .exclude
126 .iter() 126 .iter()
127 .map(|glob| crate::vfs_glob::Glob::new(glob)) 127 .map(|glob| crate::vfs_glob::Glob::new(glob))
128 .collect::<std::result::Result<Vec<_>, _>>()?; 128 .collect::<std::result::Result<Vec<_>, _>>()?;
129 129
130 if config.use_client_watching { 130 if let FilesWatcher::Client = config.files.watcher {
131 let registration_options = req::DidChangeWatchedFilesRegistrationOptions { 131 let registration_options = req::DidChangeWatchedFilesRegistrationOptions {
132 watchers: workspaces 132 watchers: workspaces
133 .iter() 133 .iter()
@@ -153,7 +153,7 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
153 workspaces, 153 workspaces,
154 config.lru_capacity, 154 config.lru_capacity,
155 &globs, 155 &globs,
156 Watch(!config.use_client_watching), 156 Watch(matches!(config.files.watcher, FilesWatcher::Notify)),
157 config, 157 config,
158 ) 158 )
159 }; 159 };
@@ -607,7 +607,12 @@ fn on_notification(
607 let request_id = loop_state.next_request_id(); 607 let request_id = loop_state.next_request_id();
608 let request = request_new::<req::WorkspaceConfiguration>( 608 let request = request_new::<req::WorkspaceConfiguration>(
609 request_id.clone(), 609 request_id.clone(),
610 ConfigurationParams::default(), 610 req::ConfigurationParams {
611 items: vec![req::ConfigurationItem {
612 scope_uri: None,
613 section: Some("rust-analyzer".to_string()),
614 }],
615 },
611 ); 616 );
612 msg_sender.send(request.into())?; 617 msg_sender.send(request.into())?;
613 loop_state.configuration_request_id = Some(request_id); 618 loop_state.configuration_request_id = Some(request_id);
diff --git a/crates/rust-analyzer/src/req.rs b/crates/rust-analyzer/src/req.rs
index ce799a683..b8b627e28 100644
--- a/crates/rust-analyzer/src/req.rs
+++ b/crates/rust-analyzer/src/req.rs
@@ -6,8 +6,8 @@ use serde::{Deserialize, Serialize};
6 6
7pub use lsp_types::{ 7pub use lsp_types::{
8 notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens, 8 notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
9 CodeLensParams, CompletionParams, CompletionResponse, ConfigurationParams, DiagnosticTag, 9 CodeLensParams, CompletionParams, CompletionResponse, ConfigurationItem, ConfigurationParams,
10 DidChangeConfigurationParams, DidChangeWatchedFilesParams, 10 DiagnosticTag, DidChangeConfigurationParams, DidChangeWatchedFilesParams,
11 DidChangeWatchedFilesRegistrationOptions, DocumentOnTypeFormattingParams, DocumentSymbolParams, 11 DidChangeWatchedFilesRegistrationOptions, DocumentOnTypeFormattingParams, DocumentSymbolParams,
12 DocumentSymbolResponse, FileSystemWatcher, Hover, InitializeResult, MessageType, 12 DocumentSymbolResponse, FileSystemWatcher, Hover, InitializeResult, MessageType,
13 PartialResultParams, ProgressParams, ProgressParamsValue, ProgressToken, 13 PartialResultParams, ProgressParams, ProgressParamsValue, ProgressToken,
diff --git a/editors/code/package.json b/editors/code/package.json
index df8adfe0e..1f95cd130 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -217,7 +217,6 @@
217 "type": "boolean", 217 "type": "boolean",
218 "markdownDescription": "Whether to show `can't find Cargo.toml` error message" 218 "markdownDescription": "Whether to show `can't find Cargo.toml` error message"
219 }, 219 },
220
221 "rust-analyzer.cargo.noDefaultFeatures": { 220 "rust-analyzer.cargo.noDefaultFeatures": {
222 "type": "boolean", 221 "type": "boolean",
223 "default": false, 222 "default": false,
@@ -272,7 +271,6 @@
272 "default": true, 271 "default": true,
273 "markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)" 272 "markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)"
274 }, 273 },
275
276 "rust-analyzer.inlayHints.typeHints": { 274 "rust-analyzer.inlayHints.typeHints": {
277 "type": "boolean", 275 "type": "boolean",
278 "default": true, 276 "default": true,
@@ -298,7 +296,6 @@
298 "exclusiveMinimum": true, 296 "exclusiveMinimum": true,
299 "description": "Maximum length for inlay hints" 297 "description": "Maximum length for inlay hints"
300 }, 298 },
301
302 "rust-analyzer.completion.addCallParenthesis": { 299 "rust-analyzer.completion.addCallParenthesis": {
303 "type": "boolean", 300 "type": "boolean",
304 "default": true, 301 "default": true,
@@ -318,7 +315,6 @@
318 "type": "boolean", 315 "type": "boolean",
319 "description": "Show function name and docs in parameter hints" 316 "description": "Show function name and docs in parameter hints"
320 }, 317 },
321
322 "rust-analyzer.highlighting.semanticTokens": { 318 "rust-analyzer.highlighting.semanticTokens": {
323 "type": "boolean", 319 "type": "boolean",
324 "default": false, 320 "default": false,
@@ -370,7 +366,7 @@
370 "description": "Enable logging of VS Code extensions itself", 366 "description": "Enable logging of VS Code extensions itself",
371 "type": "boolean", 367 "type": "boolean",
372 "default": false 368 "default": false
373 }, 369 }
374 } 370 }
375 }, 371 },
376 "problemPatterns": [ 372 "problemPatterns": [
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 8ddc1cdca..3b1d00bca 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -5,30 +5,6 @@ import { Config } from './config';
5import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed'; 5import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
6import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed'; 6import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed';
7 7
8export function configToServerOptions(config: Config) {
9 return {
10 lruCapacity: config.lruCapacity,
11
12 inlayHintsType: config.inlayHints.typeHints,
13 inlayHintsParameter: config.inlayHints.parameterHints,
14 inlayHintsChaining: config.inlayHints.chainingHints,
15 inlayHintsMaxLength: config.inlayHints.maxLength,
16
17 cargoWatchEnable: config.cargoWatchOptions.enable,
18 cargoWatchArgs: config.cargoWatchOptions.arguments,
19 cargoWatchCommand: config.cargoWatchOptions.command,
20 cargoWatchAllTargets: config.cargoWatchOptions.allTargets,
21
22 excludeGlobs: config.excludeGlobs,
23 useClientWatching: config.useClientWatching,
24 featureFlags: config.featureFlags,
25 withSysroot: config.withSysroot,
26 cargoFeatures: config.cargoFeatures,
27 rustfmtArgs: config.rustfmtArgs,
28 vscodeLldb: vscode.extensions.getExtension("vadimcn.vscode-lldb") != null,
29 };
30}
31
32export async function createClient(config: Config, serverPath: string, cwd: string): Promise<lc.LanguageClient> { 8export async function createClient(config: Config, serverPath: string, cwd: string): Promise<lc.LanguageClient> {
33 // '.' Is the fallback if no folder is open 9 // '.' Is the fallback if no folder is open
34 // TODO?: Workspace folders support Uri's (eg: file://test.txt). 10 // TODO?: Workspace folders support Uri's (eg: file://test.txt).
@@ -48,7 +24,7 @@ export async function createClient(config: Config, serverPath: string, cwd: stri
48 24
49 const clientOptions: lc.LanguageClientOptions = { 25 const clientOptions: lc.LanguageClientOptions = {
50 documentSelector: [{ scheme: 'file', language: 'rust' }], 26 documentSelector: [{ scheme: 'file', language: 'rust' }],
51 initializationOptions: configToServerOptions(config), 27 initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"),
52 traceOutputChannel, 28 traceOutputChannel,
53 middleware: { 29 middleware: {
54 // Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576 30 // Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index c37c6276b..1f45f1de0 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -11,9 +11,8 @@ export class Config {
11 private readonly rootSection = "rust-analyzer"; 11 private readonly rootSection = "rust-analyzer";
12 private readonly requiresReloadOpts = [ 12 private readonly requiresReloadOpts = [
13 "serverPath", 13 "serverPath",
14 "cargoFeatures", 14 "cargo",
15 "excludeGlobs", 15 "files",
16 "useClientWatching",
17 "highlighting", 16 "highlighting",
18 "updates.channel", 17 "updates.channel",
19 ] 18 ]
@@ -71,17 +70,8 @@ export class Config {
71 get channel() { return this.cfg.get<UpdatesChannel>("updates.channel")!; } 70 get channel() { return this.cfg.get<UpdatesChannel>("updates.channel")!; }
72 get askBeforeDownload() { return this.cfg.get<boolean>("updates.askBeforeDownload")!; } 71 get askBeforeDownload() { return this.cfg.get<boolean>("updates.askBeforeDownload")!; }
73 get highlightingSemanticTokens() { return this.cfg.get<boolean>("highlighting.semanticTokens")!; } 72 get highlightingSemanticTokens() { return this.cfg.get<boolean>("highlighting.semanticTokens")!; }
74 get lruCapacity() { return this.cfg.get<null | number>("lruCapacity")!; }
75 get excludeGlobs() { return this.cfg.get<string[]>("excludeGlobs")!; }
76 get useClientWatching() { return this.cfg.get<boolean>("useClientWatching")!; }
77 get featureFlags() { return this.cfg.get<Record<string, boolean>>("featureFlags")!; }
78 get rustfmtArgs() { return this.cfg.get<string[]>("rustfmtArgs")!; }
79 get loadOutDirsFromCheck() { return this.cfg.get<boolean>("loadOutDirsFromCheck")!; }
80 get traceExtension() { return this.cfg.get<boolean>("trace.extension")!; } 73 get traceExtension() { return this.cfg.get<boolean>("trace.extension")!; }
81 74
82 // for internal use
83 get withSysroot() { return this.cfg.get<boolean>("withSysroot", true)!; }
84
85 get inlayHints() { 75 get inlayHints() {
86 return { 76 return {
87 typeHints: this.cfg.get<boolean>("inlayHints.typeHints")!, 77 typeHints: this.cfg.get<boolean>("inlayHints.typeHints")!,
@@ -91,21 +81,9 @@ export class Config {
91 }; 81 };
92 } 82 }
93 83
94 get cargoWatchOptions() { 84 get checkOnSave() {
95 return {
96 enable: this.cfg.get<boolean>("cargo-watch.enable")!,
97 arguments: this.cfg.get<string[]>("cargo-watch.arguments")!,
98 allTargets: this.cfg.get<boolean>("cargo-watch.allTargets")!,
99 command: this.cfg.get<string>("cargo-watch.command")!,
100 };
101 }
102
103 get cargoFeatures() {
104 return { 85 return {
105 noDefaultFeatures: this.cfg.get<boolean>("cargoFeatures.noDefaultFeatures")!, 86 command: this.cfg.get<string>("checkOnSave.command")!,
106 allFeatures: this.cfg.get<boolean>("cargoFeatures.allFeatures")!,
107 features: this.cfg.get<string[]>("cargoFeatures.features")!,
108 loadOutDirsFromCheck: this.cfg.get<boolean>("cargoFeatures.loadOutDirsFromCheck")!,
109 }; 87 };
110 } 88 }
111} 89}
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 86b5f3629..bd1c3de07 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3 3
4import { Config } from './config'; 4import { Config } from './config';
5import { createClient, configToServerOptions } from './client'; 5import { createClient } from './client';
6import { isRustEditor, RustEditor } from './util'; 6import { isRustEditor, RustEditor } from './util';
7 7
8export class Ctx { 8export class Ctx {
@@ -25,7 +25,6 @@ export class Ctx {
25 const res = new Ctx(config, extCtx, client, serverPath); 25 const res = new Ctx(config, extCtx, client, serverPath);
26 res.pushCleanup(client.start()); 26 res.pushCleanup(client.start());
27 await client.onReady(); 27 await client.onReady();
28 client.onRequest('workspace/configuration', _ => [configToServerOptions(config)]);
29 return res; 28 return res;
30 } 29 }
31 30
diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts
index 0f5f6ef99..f9cadc8a2 100644
--- a/editors/code/src/status_display.ts
+++ b/editors/code/src/status_display.ts
@@ -7,7 +7,7 @@ import { Ctx } from './ctx';
7const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; 7const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
8 8
9export function activateStatusDisplay(ctx: Ctx) { 9export function activateStatusDisplay(ctx: Ctx) {
10 const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command); 10 const statusDisplay = new StatusDisplay(ctx.config.checkOnSave.command);
11 ctx.pushCleanup(statusDisplay); 11 ctx.pushCleanup(statusDisplay);
12 const client = ctx.client; 12 const client = ctx.client;
13 if (client != null) { 13 if (client != null) {