mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
vscode: moved to getters as per matklad
This commit is contained in:
parent
fd37151ade
commit
4fb427743c
5 changed files with 32 additions and 38 deletions
|
@ -10,7 +10,7 @@ export async function createClient(config: Config): Promise<null | lc.LanguageCl
|
||||||
// It might be a good idea to test if the uri points to a file.
|
// It might be a good idea to test if the uri points to a file.
|
||||||
const workspaceFolderPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.';
|
const workspaceFolderPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.';
|
||||||
|
|
||||||
const langServerPath = await ensureLanguageServerBinary(config.langServerBinarySource());
|
const langServerPath = await ensureLanguageServerBinary(config.langServerBinarySource);
|
||||||
if (!langServerPath) return null;
|
if (!langServerPath) return null;
|
||||||
|
|
||||||
const run: lc.Executable = {
|
const run: lc.Executable = {
|
||||||
|
@ -24,23 +24,23 @@ export async function createClient(config: Config): Promise<null | lc.LanguageCl
|
||||||
const traceOutputChannel = vscode.window.createOutputChannel(
|
const traceOutputChannel = vscode.window.createOutputChannel(
|
||||||
'Rust Analyzer Language Server Trace',
|
'Rust Analyzer Language Server Trace',
|
||||||
);
|
);
|
||||||
const cargoWatchOpts = config.cargoWatchOptions();
|
const cargoWatchOpts = config.cargoWatchOptions;
|
||||||
|
|
||||||
const clientOptions: lc.LanguageClientOptions = {
|
const clientOptions: lc.LanguageClientOptions = {
|
||||||
documentSelector: [{ scheme: 'file', language: 'rust' }],
|
documentSelector: [{ scheme: 'file', language: 'rust' }],
|
||||||
initializationOptions: {
|
initializationOptions: {
|
||||||
publishDecorations: true,
|
publishDecorations: true,
|
||||||
lruCapacity: config.lruCapacity(),
|
lruCapacity: config.lruCapacity,
|
||||||
maxInlayHintLength: config.maxInlayHintLength(),
|
maxInlayHintLength: config.maxInlayHintLength,
|
||||||
cargoWatchEnable: cargoWatchOpts.enable,
|
cargoWatchEnable: cargoWatchOpts.enable,
|
||||||
cargoWatchArgs: cargoWatchOpts.arguments,
|
cargoWatchArgs: cargoWatchOpts.arguments,
|
||||||
cargoWatchCommand: cargoWatchOpts.command,
|
cargoWatchCommand: cargoWatchOpts.command,
|
||||||
cargoWatchAllTargets: cargoWatchOpts.allTargets,
|
cargoWatchAllTargets: cargoWatchOpts.allTargets,
|
||||||
excludeGlobs: config.excludeGlobs(),
|
excludeGlobs: config.excludeGlobs,
|
||||||
useClientWatching: config.useClientWatching(),
|
useClientWatching: config.useClientWatching,
|
||||||
featureFlags: config.featureFlags(),
|
featureFlags: config.featureFlags,
|
||||||
withSysroot: config.withSysroot(),
|
withSysroot: config.withSysroot,
|
||||||
cargoFeatures: config.cargoFeatures(),
|
cargoFeatures: config.cargoFeatures,
|
||||||
},
|
},
|
||||||
traceOutputChannel,
|
traceOutputChannel,
|
||||||
};
|
};
|
||||||
|
|
|
@ -68,17 +68,14 @@ export class Config {
|
||||||
* `platform` on GitHub releases. (It is also stored under the same name when
|
* `platform` on GitHub releases. (It is also stored under the same name when
|
||||||
* downloaded by the extension).
|
* downloaded by the extension).
|
||||||
*/
|
*/
|
||||||
private static prebuiltLangServerFileName(
|
get prebuiltLangServerFileName(): null | string {
|
||||||
platform: NodeJS.Platform,
|
|
||||||
arch: string
|
|
||||||
): null | string {
|
|
||||||
// See possible `arch` values here:
|
// See possible `arch` values here:
|
||||||
// https://nodejs.org/api/process.html#process_process_arch
|
// https://nodejs.org/api/process.html#process_process_arch
|
||||||
|
|
||||||
switch (platform) {
|
switch (process.platform) {
|
||||||
|
|
||||||
case "linux": {
|
case "linux": {
|
||||||
switch (arch) {
|
switch (process.arch) {
|
||||||
case "arm":
|
case "arm":
|
||||||
case "arm64": return null;
|
case "arm64": return null;
|
||||||
|
|
||||||
|
@ -101,7 +98,7 @@ export class Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
langServerBinarySource(): null | BinarySource {
|
get langServerBinarySource(): null | BinarySource {
|
||||||
const langServerPath = RA_LSP_DEBUG ?? this.cfg.get<null | string>("raLspServerPath");
|
const langServerPath = RA_LSP_DEBUG ?? this.cfg.get<null | string>("raLspServerPath");
|
||||||
|
|
||||||
if (langServerPath) {
|
if (langServerPath) {
|
||||||
|
@ -111,9 +108,7 @@ export class Config {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const prebuiltBinaryName = Config.prebuiltLangServerFileName(
|
const prebuiltBinaryName = this.prebuiltLangServerFileName;
|
||||||
process.platform, process.arch
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!prebuiltBinaryName) return null;
|
if (!prebuiltBinaryName) return null;
|
||||||
|
|
||||||
|
@ -131,17 +126,16 @@ export class Config {
|
||||||
// We don't do runtime config validation here for simplicity. More on stackoverflow:
|
// We don't do runtime config validation here for simplicity. More on stackoverflow:
|
||||||
// https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension
|
// https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension
|
||||||
|
|
||||||
// FIXME: add codegen for primitive configurations
|
get highlightingOn() { return this.cfg.get("highlightingOn") as boolean; }
|
||||||
highlightingOn() { return this.cfg.get("highlightingOn") as boolean; }
|
get rainbowHighlightingOn() { return this.cfg.get("rainbowHighlightingOn") as boolean; }
|
||||||
rainbowHighlightingOn() { return this.cfg.get("rainbowHighlightingOn") as boolean; }
|
get lruCapacity() { return this.cfg.get("lruCapacity") as null | number; }
|
||||||
lruCapacity() { return this.cfg.get("lruCapacity") as null | number; }
|
get displayInlayHints() { return this.cfg.get("displayInlayHints") as boolean; }
|
||||||
displayInlayHints() { return this.cfg.get("displayInlayHints") as boolean; }
|
get maxInlayHintLength() { return this.cfg.get("maxInlayHintLength") as number; }
|
||||||
maxInlayHintLength() { return this.cfg.get("maxInlayHintLength") as number; }
|
get excludeGlobs() { return this.cfg.get("excludeGlobs") as string[]; }
|
||||||
excludeGlobs() { return this.cfg.get("excludeGlobs") as string[]; }
|
get useClientWatching() { return this.cfg.get("useClientWatching") as boolean; }
|
||||||
useClientWatching() { return this.cfg.get("useClientWatching") as boolean; }
|
get featureFlags() { return this.cfg.get("featureFlags") as Record<string, boolean>; }
|
||||||
featureFlags() { return this.cfg.get("featureFlags") as Record<string, boolean>; }
|
|
||||||
|
|
||||||
cargoWatchOptions(): CargoWatchOptions {
|
get cargoWatchOptions(): CargoWatchOptions {
|
||||||
return {
|
return {
|
||||||
enable: this.cfg.get("cargo-watch.enable") as boolean,
|
enable: this.cfg.get("cargo-watch.enable") as boolean,
|
||||||
arguments: this.cfg.get("cargo-watch.arguments") as string[],
|
arguments: this.cfg.get("cargo-watch.arguments") as string[],
|
||||||
|
@ -150,7 +144,7 @@ export class Config {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
cargoFeatures(): CargoFeatures {
|
get cargoFeatures(): CargoFeatures {
|
||||||
return {
|
return {
|
||||||
noDefaultFeatures: this.cfg.get("cargoFeatures.noDefaultFeatures") as boolean,
|
noDefaultFeatures: this.cfg.get("cargoFeatures.noDefaultFeatures") as boolean,
|
||||||
allFeatures: this.cfg.get("cargoFeatures.allFeatures") as boolean,
|
allFeatures: this.cfg.get("cargoFeatures.allFeatures") as boolean,
|
||||||
|
@ -159,5 +153,5 @@ export class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
// for internal use
|
// for internal use
|
||||||
withSysroot() { return this.cfg.get("withSysroot", false); }
|
get withSysroot() { return this.cfg.get("withSysroot", false); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ export function activateHighlighting(ctx: Ctx) {
|
||||||
client.onNotification(
|
client.onNotification(
|
||||||
'rust-analyzer/publishDecorations',
|
'rust-analyzer/publishDecorations',
|
||||||
(params: PublishDecorationsParams) => {
|
(params: PublishDecorationsParams) => {
|
||||||
if (!ctx.config.highlightingOn()) return;
|
if (!ctx.config.highlightingOn) return;
|
||||||
|
|
||||||
const targetEditor = vscode.window.visibleTextEditors.find(
|
const targetEditor = vscode.window.visibleTextEditors.find(
|
||||||
editor => {
|
editor => {
|
||||||
|
@ -39,7 +39,7 @@ export function activateHighlighting(ctx: Ctx) {
|
||||||
vscode.window.onDidChangeActiveTextEditor(
|
vscode.window.onDidChangeActiveTextEditor(
|
||||||
async (editor: vscode.TextEditor | undefined) => {
|
async (editor: vscode.TextEditor | undefined) => {
|
||||||
if (!editor || editor.document.languageId !== 'rust') return;
|
if (!editor || editor.document.languageId !== 'rust') return;
|
||||||
if (!ctx.config.highlightingOn()) return;
|
if (!ctx.config.highlightingOn) return;
|
||||||
const client = ctx.client;
|
const client = ctx.client;
|
||||||
if (!client) return;
|
if (!client) return;
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ class Highlighter {
|
||||||
string,
|
string,
|
||||||
[vscode.Range[], boolean]
|
[vscode.Range[], boolean]
|
||||||
> = new Map();
|
> = new Map();
|
||||||
const rainbowTime = this.ctx.config.rainbowHighlightingOn();
|
const rainbowTime = this.ctx.config.rainbowHighlightingOn;
|
||||||
|
|
||||||
for (const tag of this.decorations.keys()) {
|
for (const tag of this.decorations.keys()) {
|
||||||
byTag.set(tag, []);
|
byTag.set(tag, []);
|
||||||
|
|
|
@ -22,12 +22,12 @@ export function activateInlayHints(ctx: Ctx) {
|
||||||
);
|
);
|
||||||
|
|
||||||
vscode.workspace.onDidChangeConfiguration(
|
vscode.workspace.onDidChangeConfiguration(
|
||||||
async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints()),
|
async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints),
|
||||||
null,
|
null,
|
||||||
ctx.subscriptions
|
ctx.subscriptions
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints()));
|
ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints));
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InlayHintsParams {
|
interface InlayHintsParams {
|
||||||
|
@ -59,7 +59,7 @@ class HintsUpdater {
|
||||||
|
|
||||||
constructor(ctx: Ctx) {
|
constructor(ctx: Ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.enabled = ctx.config.displayInlayHints();
|
this.enabled = ctx.config.displayInlayHints;
|
||||||
}
|
}
|
||||||
|
|
||||||
async setEnabled(enabled: boolean) {
|
async setEnabled(enabled: boolean) {
|
||||||
|
|
|
@ -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.cargoWatchOptions.command);
|
||||||
ctx.pushCleanup(statusDisplay);
|
ctx.pushCleanup(statusDisplay);
|
||||||
ctx.onDidRestart(client => ctx.pushCleanup(client.onProgress(
|
ctx.onDidRestart(client => ctx.pushCleanup(client.onProgress(
|
||||||
WorkDoneProgress.type,
|
WorkDoneProgress.type,
|
||||||
|
|
Loading…
Reference in a new issue