mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Lean onto default implementation of configs
This commit is contained in:
parent
e4cf40a152
commit
48c58309cc
8 changed files with 24 additions and 70 deletions
|
@ -38,12 +38,12 @@ pub struct Config {
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct FilesConfig {
|
pub struct FilesConfig {
|
||||||
watcher: FilesWatcher,
|
pub watcher: FilesWatcher,
|
||||||
exclude: Vec<String>,
|
pub exclude: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum FilesWatcher {
|
pub enum FilesWatcher {
|
||||||
Client,
|
Client,
|
||||||
Notify,
|
Notify,
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ use serde::{de::DeserializeOwned, Serialize};
|
||||||
use threadpool::ThreadPool;
|
use threadpool::ThreadPool;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
config::{Config, FilesWatcher},
|
||||||
diagnostics::DiagnosticTask,
|
diagnostics::DiagnosticTask,
|
||||||
main_loop::{
|
main_loop::{
|
||||||
pending_requests::{PendingRequest, PendingRequests},
|
pending_requests::{PendingRequest, PendingRequests},
|
||||||
|
@ -40,7 +40,6 @@ use crate::{
|
||||||
world::{WorldSnapshot, WorldState},
|
world::{WorldSnapshot, WorldState},
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
use req::ConfigurationParams;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct LspError {
|
pub struct LspError {
|
||||||
|
@ -122,12 +121,13 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
|
||||||
};
|
};
|
||||||
|
|
||||||
let globs = config
|
let globs = config
|
||||||
.exclude_globs
|
.files
|
||||||
|
.exclude
|
||||||
.iter()
|
.iter()
|
||||||
.map(|glob| crate::vfs_glob::Glob::new(glob))
|
.map(|glob| crate::vfs_glob::Glob::new(glob))
|
||||||
.collect::<std::result::Result<Vec<_>, _>>()?;
|
.collect::<std::result::Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
if config.use_client_watching {
|
if let FilesWatcher::Client = config.files.watcher {
|
||||||
let registration_options = req::DidChangeWatchedFilesRegistrationOptions {
|
let registration_options = req::DidChangeWatchedFilesRegistrationOptions {
|
||||||
watchers: workspaces
|
watchers: workspaces
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -153,7 +153,7 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
|
||||||
workspaces,
|
workspaces,
|
||||||
config.lru_capacity,
|
config.lru_capacity,
|
||||||
&globs,
|
&globs,
|
||||||
Watch(!config.use_client_watching),
|
Watch(matches!(config.files.watcher, FilesWatcher::Notify)),
|
||||||
config,
|
config,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
@ -607,7 +607,12 @@ fn on_notification(
|
||||||
let request_id = loop_state.next_request_id();
|
let request_id = loop_state.next_request_id();
|
||||||
let request = request_new::<req::WorkspaceConfiguration>(
|
let request = request_new::<req::WorkspaceConfiguration>(
|
||||||
request_id.clone(),
|
request_id.clone(),
|
||||||
ConfigurationParams::default(),
|
req::ConfigurationParams {
|
||||||
|
items: vec![req::ConfigurationItem {
|
||||||
|
scope_uri: None,
|
||||||
|
section: Some("rust-analyzer".to_string()),
|
||||||
|
}],
|
||||||
|
},
|
||||||
);
|
);
|
||||||
msg_sender.send(request.into())?;
|
msg_sender.send(request.into())?;
|
||||||
loop_state.configuration_request_id = Some(request_id);
|
loop_state.configuration_request_id = Some(request_id);
|
||||||
|
|
|
@ -6,8 +6,8 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub use lsp_types::{
|
pub use lsp_types::{
|
||||||
notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
|
notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
|
||||||
CodeLensParams, CompletionParams, CompletionResponse, ConfigurationParams, DiagnosticTag,
|
CodeLensParams, CompletionParams, CompletionResponse, ConfigurationItem, ConfigurationParams,
|
||||||
DidChangeConfigurationParams, DidChangeWatchedFilesParams,
|
DiagnosticTag, DidChangeConfigurationParams, DidChangeWatchedFilesParams,
|
||||||
DidChangeWatchedFilesRegistrationOptions, DocumentOnTypeFormattingParams, DocumentSymbolParams,
|
DidChangeWatchedFilesRegistrationOptions, DocumentOnTypeFormattingParams, DocumentSymbolParams,
|
||||||
DocumentSymbolResponse, FileSystemWatcher, Hover, InitializeResult, MessageType,
|
DocumentSymbolResponse, FileSystemWatcher, Hover, InitializeResult, MessageType,
|
||||||
PartialResultParams, ProgressParams, ProgressParamsValue, ProgressToken,
|
PartialResultParams, ProgressParams, ProgressParamsValue, ProgressToken,
|
||||||
|
|
|
@ -217,7 +217,6 @@
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"markdownDescription": "Whether to show `can't find Cargo.toml` error message"
|
"markdownDescription": "Whether to show `can't find Cargo.toml` error message"
|
||||||
},
|
},
|
||||||
|
|
||||||
"rust-analyzer.cargo.noDefaultFeatures": {
|
"rust-analyzer.cargo.noDefaultFeatures": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
|
@ -272,7 +271,6 @@
|
||||||
"default": true,
|
"default": true,
|
||||||
"markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)"
|
"markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)"
|
||||||
},
|
},
|
||||||
|
|
||||||
"rust-analyzer.inlayHints.typeHints": {
|
"rust-analyzer.inlayHints.typeHints": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
|
@ -298,7 +296,6 @@
|
||||||
"exclusiveMinimum": true,
|
"exclusiveMinimum": true,
|
||||||
"description": "Maximum length for inlay hints"
|
"description": "Maximum length for inlay hints"
|
||||||
},
|
},
|
||||||
|
|
||||||
"rust-analyzer.completion.addCallParenthesis": {
|
"rust-analyzer.completion.addCallParenthesis": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
|
@ -318,7 +315,6 @@
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Show function name and docs in parameter hints"
|
"description": "Show function name and docs in parameter hints"
|
||||||
},
|
},
|
||||||
|
|
||||||
"rust-analyzer.highlighting.semanticTokens": {
|
"rust-analyzer.highlighting.semanticTokens": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
|
@ -370,7 +366,7 @@
|
||||||
"description": "Enable logging of VS Code extensions itself",
|
"description": "Enable logging of VS Code extensions itself",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"problemPatterns": [
|
"problemPatterns": [
|
||||||
|
|
|
@ -5,30 +5,6 @@ import { Config } from './config';
|
||||||
import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
|
import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
|
||||||
import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed';
|
import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed';
|
||||||
|
|
||||||
export function configToServerOptions(config: Config) {
|
|
||||||
return {
|
|
||||||
lruCapacity: config.lruCapacity,
|
|
||||||
|
|
||||||
inlayHintsType: config.inlayHints.typeHints,
|
|
||||||
inlayHintsParameter: config.inlayHints.parameterHints,
|
|
||||||
inlayHintsChaining: config.inlayHints.chainingHints,
|
|
||||||
inlayHintsMaxLength: config.inlayHints.maxLength,
|
|
||||||
|
|
||||||
cargoWatchEnable: config.cargoWatchOptions.enable,
|
|
||||||
cargoWatchArgs: config.cargoWatchOptions.arguments,
|
|
||||||
cargoWatchCommand: config.cargoWatchOptions.command,
|
|
||||||
cargoWatchAllTargets: config.cargoWatchOptions.allTargets,
|
|
||||||
|
|
||||||
excludeGlobs: config.excludeGlobs,
|
|
||||||
useClientWatching: config.useClientWatching,
|
|
||||||
featureFlags: config.featureFlags,
|
|
||||||
withSysroot: config.withSysroot,
|
|
||||||
cargoFeatures: config.cargoFeatures,
|
|
||||||
rustfmtArgs: config.rustfmtArgs,
|
|
||||||
vscodeLldb: vscode.extensions.getExtension("vadimcn.vscode-lldb") != null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createClient(config: Config, serverPath: string, cwd: string): Promise<lc.LanguageClient> {
|
export async function createClient(config: Config, serverPath: string, cwd: string): Promise<lc.LanguageClient> {
|
||||||
// '.' Is the fallback if no folder is open
|
// '.' Is the fallback if no folder is open
|
||||||
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
|
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
|
||||||
|
@ -48,7 +24,7 @@ export async function createClient(config: Config, serverPath: string, cwd: stri
|
||||||
|
|
||||||
const clientOptions: lc.LanguageClientOptions = {
|
const clientOptions: lc.LanguageClientOptions = {
|
||||||
documentSelector: [{ scheme: 'file', language: 'rust' }],
|
documentSelector: [{ scheme: 'file', language: 'rust' }],
|
||||||
initializationOptions: configToServerOptions(config),
|
initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"),
|
||||||
traceOutputChannel,
|
traceOutputChannel,
|
||||||
middleware: {
|
middleware: {
|
||||||
// Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576
|
// Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576
|
||||||
|
|
|
@ -11,9 +11,8 @@ export class Config {
|
||||||
private readonly rootSection = "rust-analyzer";
|
private readonly rootSection = "rust-analyzer";
|
||||||
private readonly requiresReloadOpts = [
|
private readonly requiresReloadOpts = [
|
||||||
"serverPath",
|
"serverPath",
|
||||||
"cargoFeatures",
|
"cargo",
|
||||||
"excludeGlobs",
|
"files",
|
||||||
"useClientWatching",
|
|
||||||
"highlighting",
|
"highlighting",
|
||||||
"updates.channel",
|
"updates.channel",
|
||||||
]
|
]
|
||||||
|
@ -71,17 +70,8 @@ export class Config {
|
||||||
get channel() { return this.cfg.get<UpdatesChannel>("updates.channel")!; }
|
get channel() { return this.cfg.get<UpdatesChannel>("updates.channel")!; }
|
||||||
get askBeforeDownload() { return this.cfg.get<boolean>("updates.askBeforeDownload")!; }
|
get askBeforeDownload() { return this.cfg.get<boolean>("updates.askBeforeDownload")!; }
|
||||||
get highlightingSemanticTokens() { return this.cfg.get<boolean>("highlighting.semanticTokens")!; }
|
get highlightingSemanticTokens() { return this.cfg.get<boolean>("highlighting.semanticTokens")!; }
|
||||||
get lruCapacity() { return this.cfg.get<null | number>("lruCapacity")!; }
|
|
||||||
get excludeGlobs() { return this.cfg.get<string[]>("excludeGlobs")!; }
|
|
||||||
get useClientWatching() { return this.cfg.get<boolean>("useClientWatching")!; }
|
|
||||||
get featureFlags() { return this.cfg.get<Record<string, boolean>>("featureFlags")!; }
|
|
||||||
get rustfmtArgs() { return this.cfg.get<string[]>("rustfmtArgs")!; }
|
|
||||||
get loadOutDirsFromCheck() { return this.cfg.get<boolean>("loadOutDirsFromCheck")!; }
|
|
||||||
get traceExtension() { return this.cfg.get<boolean>("trace.extension")!; }
|
get traceExtension() { return this.cfg.get<boolean>("trace.extension")!; }
|
||||||
|
|
||||||
// for internal use
|
|
||||||
get withSysroot() { return this.cfg.get<boolean>("withSysroot", true)!; }
|
|
||||||
|
|
||||||
get inlayHints() {
|
get inlayHints() {
|
||||||
return {
|
return {
|
||||||
typeHints: this.cfg.get<boolean>("inlayHints.typeHints")!,
|
typeHints: this.cfg.get<boolean>("inlayHints.typeHints")!,
|
||||||
|
@ -91,21 +81,9 @@ export class Config {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
get cargoWatchOptions() {
|
get checkOnSave() {
|
||||||
return {
|
return {
|
||||||
enable: this.cfg.get<boolean>("cargo-watch.enable")!,
|
command: this.cfg.get<string>("checkOnSave.command")!,
|
||||||
arguments: this.cfg.get<string[]>("cargo-watch.arguments")!,
|
|
||||||
allTargets: this.cfg.get<boolean>("cargo-watch.allTargets")!,
|
|
||||||
command: this.cfg.get<string>("cargo-watch.command")!,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
get cargoFeatures() {
|
|
||||||
return {
|
|
||||||
noDefaultFeatures: this.cfg.get<boolean>("cargoFeatures.noDefaultFeatures")!,
|
|
||||||
allFeatures: this.cfg.get<boolean>("cargoFeatures.allFeatures")!,
|
|
||||||
features: this.cfg.get<string[]>("cargoFeatures.features")!,
|
|
||||||
loadOutDirsFromCheck: this.cfg.get<boolean>("cargoFeatures.loadOutDirsFromCheck")!,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as vscode from 'vscode';
|
||||||
import * as lc from 'vscode-languageclient';
|
import * as lc from 'vscode-languageclient';
|
||||||
|
|
||||||
import { Config } from './config';
|
import { Config } from './config';
|
||||||
import { createClient, configToServerOptions } from './client';
|
import { createClient } from './client';
|
||||||
import { isRustEditor, RustEditor } from './util';
|
import { isRustEditor, RustEditor } from './util';
|
||||||
|
|
||||||
export class Ctx {
|
export class Ctx {
|
||||||
|
@ -25,7 +25,6 @@ export class Ctx {
|
||||||
const res = new Ctx(config, extCtx, client, serverPath);
|
const res = new Ctx(config, extCtx, client, serverPath);
|
||||||
res.pushCleanup(client.start());
|
res.pushCleanup(client.start());
|
||||||
await client.onReady();
|
await client.onReady();
|
||||||
client.onRequest('workspace/configuration', _ => [configToServerOptions(config)]);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { Ctx } from './ctx';
|
||||||
const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
||||||
|
|
||||||
export function activateStatusDisplay(ctx: Ctx) {
|
export function activateStatusDisplay(ctx: Ctx) {
|
||||||
const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command);
|
const statusDisplay = new StatusDisplay(ctx.config.checkOnSave.command);
|
||||||
ctx.pushCleanup(statusDisplay);
|
ctx.pushCleanup(statusDisplay);
|
||||||
const client = ctx.client;
|
const client = ctx.client;
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
|
|
Loading…
Reference in a new issue