Lean onto default implementation of configs
This commit is contained in:
@@ -5,30 +5,6 @@ import { Config } from './config';
|
||||
import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.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> {
|
||||
// '.' Is the fallback if no folder is open
|
||||
// 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 = {
|
||||
documentSelector: [{ scheme: 'file', language: 'rust' }],
|
||||
initializationOptions: configToServerOptions(config),
|
||||
initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"),
|
||||
traceOutputChannel,
|
||||
middleware: {
|
||||
// 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 requiresReloadOpts = [
|
||||
"serverPath",
|
||||
"cargoFeatures",
|
||||
"excludeGlobs",
|
||||
"useClientWatching",
|
||||
"cargo",
|
||||
"files",
|
||||
"highlighting",
|
||||
"updates.channel",
|
||||
]
|
||||
@@ -71,17 +70,8 @@ export class Config {
|
||||
get channel() { return this.cfg.get<UpdatesChannel>("updates.channel")!; }
|
||||
get askBeforeDownload() { return this.cfg.get<boolean>("updates.askBeforeDownload")!; }
|
||||
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")!; }
|
||||
|
||||
// for internal use
|
||||
get withSysroot() { return this.cfg.get<boolean>("withSysroot", true)!; }
|
||||
|
||||
get inlayHints() {
|
||||
return {
|
||||
typeHints: this.cfg.get<boolean>("inlayHints.typeHints")!,
|
||||
@@ -91,21 +81,9 @@ export class Config {
|
||||
};
|
||||
}
|
||||
|
||||
get cargoWatchOptions() {
|
||||
get checkOnSave() {
|
||||
return {
|
||||
enable: this.cfg.get<boolean>("cargo-watch.enable")!,
|
||||
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")!,
|
||||
command: this.cfg.get<string>("checkOnSave.command")!,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
|
||||
import * as lc from 'vscode-languageclient';
|
||||
|
||||
import { Config } from './config';
|
||||
import { createClient, configToServerOptions } from './client';
|
||||
import { createClient } from './client';
|
||||
import { isRustEditor, RustEditor } from './util';
|
||||
|
||||
export class Ctx {
|
||||
@@ -25,7 +25,6 @@ export class Ctx {
|
||||
const res = new Ctx(config, extCtx, client, serverPath);
|
||||
res.pushCleanup(client.start());
|
||||
await client.onReady();
|
||||
client.onRequest('workspace/configuration', _ => [configToServerOptions(config)]);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Ctx } from './ctx';
|
||||
const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
||||
|
||||
export function activateStatusDisplay(ctx: Ctx) {
|
||||
const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command);
|
||||
const statusDisplay = new StatusDisplay(ctx.config.checkOnSave.command);
|
||||
ctx.pushCleanup(statusDisplay);
|
||||
const client = ctx.client;
|
||||
if (client != null) {
|
||||
|
||||
Reference in New Issue
Block a user