mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
vscode: yet another refactor commit
This commit is contained in:
parent
c9e1aab880
commit
b89b22e43e
7 changed files with 30 additions and 35 deletions
2
editors/code/package-lock.json
generated
2
editors/code/package-lock.json
generated
|
@ -878,7 +878,7 @@
|
|||
"vscode-languageclient": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-6.1.0.tgz",
|
||||
"integrity": "sha512-Tcp0VoOaa0YzxL4nEfK9tsmcy76Eo8jNLvFQZwh2c8oMm02luL8uGYPLQNAiZ3XGgegfcwiQFZMqbW7DNV0vxA==",
|
||||
"integrity": "sha1-7mfAt4GMQs4CgVctBcia38xPWjg=",
|
||||
"requires": {
|
||||
"semver": "^6.3.0",
|
||||
"vscode-languageserver-protocol": "^3.15.2"
|
||||
|
|
|
@ -7,25 +7,21 @@ import { Config } from './config';
|
|||
|
||||
export function createClient(config: Config): lc.LanguageClient {
|
||||
// '.' Is the fallback if no folder is open
|
||||
// TODO?: Workspace folders support Uri's (eg: file://test.txt). It might be a good idea to test if the uri points to a file.
|
||||
let folder: string = '.';
|
||||
if (workspace.workspaceFolders !== undefined) {
|
||||
folder = workspace.workspaceFolders[0].uri.fsPath.toString();
|
||||
}
|
||||
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
|
||||
// It might be a good idea to test if the uri points to a file.
|
||||
const workspaceFolderPath = workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.';
|
||||
|
||||
const command = expandPathResolving(config.raLspServerPath);
|
||||
if (spawnSync(command, ["--version"]).status !== 0) {
|
||||
const raLspServerPath = expandPathResolving(config.raLspServerPath);
|
||||
if (spawnSync(raLspServerPath, ["--version"]).status !== 0) {
|
||||
window.showErrorMessage(
|
||||
`Unable to execute '${command} --version'
|
||||
|
||||
Perhaps it is not in $PATH?
|
||||
|
||||
PATH=${process.env.PATH}
|
||||
`);
|
||||
`Unable to execute '${raLspServerPath} --version'\n\n` +
|
||||
`Perhaps it is not in $PATH?\n\n` +
|
||||
`PATH=${process.env.PATH}\n`
|
||||
);
|
||||
}
|
||||
const run: lc.Executable = {
|
||||
command,
|
||||
options: { cwd: folder },
|
||||
command: raLspServerPath,
|
||||
options: { cwd: workspaceFolderPath },
|
||||
};
|
||||
const serverOptions: lc.ServerOptions = {
|
||||
run,
|
||||
|
@ -43,8 +39,7 @@ PATH=${process.env.PATH}
|
|||
cargoWatchEnable: config.cargoWatchOptions.enable,
|
||||
cargoWatchArgs: config.cargoWatchOptions.arguments,
|
||||
cargoWatchCommand: config.cargoWatchOptions.command,
|
||||
cargoWatchAllTargets:
|
||||
config.cargoWatchOptions.allTargets,
|
||||
cargoWatchAllTargets: config.cargoWatchOptions.allTargets,
|
||||
excludeGlobs: config.excludeGlobs,
|
||||
useClientWatching: config.useClientWatching,
|
||||
featureFlags: config.featureFlags,
|
||||
|
|
|
@ -33,6 +33,7 @@ export class ColorTheme {
|
|||
: typeof rule.scope === 'string'
|
||||
? [rule.scope]
|
||||
: rule.scope;
|
||||
|
||||
for (const scope of scopes) {
|
||||
res.rules.set(scope, rule.settings);
|
||||
}
|
||||
|
@ -69,13 +70,13 @@ function loadThemeNamed(themeName: string): ColorTheme {
|
|||
);
|
||||
}
|
||||
|
||||
const themePaths = vscode.extensions.all
|
||||
const themePaths: string[] = vscode.extensions.all
|
||||
.filter(isTheme)
|
||||
.flatMap(ext => {
|
||||
return ext.packageJSON.contributes.themes
|
||||
.flatMap(
|
||||
ext => ext.packageJSON.contributes.themes
|
||||
.filter((it: any) => (it.id || it.label) === themeName)
|
||||
.map((it: any) => path.join(ext.extensionPath, it.path));
|
||||
});
|
||||
.map((it: any) => path.join(ext.extensionPath, it.path))
|
||||
);
|
||||
|
||||
const res = new ColorTheme();
|
||||
for (const themePath of themePaths) {
|
||||
|
@ -96,13 +97,12 @@ function loadThemeFile(themePath: string): ColorTheme {
|
|||
return new ColorTheme();
|
||||
}
|
||||
const obj = jsonc.parse(text);
|
||||
const tokenColors = obj?.tokenColors ?? [];
|
||||
const tokenColors: TextMateRule[] = obj?.tokenColors ?? [];
|
||||
const res = ColorTheme.fromRules(tokenColors);
|
||||
|
||||
for (const include in obj?.include ?? []) {
|
||||
for (const include of obj?.include ?? []) {
|
||||
const includePath = path.join(path.dirname(themePath), include);
|
||||
const tmp = loadThemeFile(includePath);
|
||||
res.mergeFrom(tmp);
|
||||
res.mergeFrom(loadThemeFile(includePath));
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
|
@ -7,7 +7,7 @@ import { Cmd, Ctx } from '../ctx';
|
|||
async function handleKeypress(ctx: Ctx) {
|
||||
const editor = ctx.activeRustEditor;
|
||||
const client = ctx.client;
|
||||
if (!editor) return false;
|
||||
|
||||
if (!editor || !client) return false;
|
||||
|
||||
const request: lc.TextDocumentPositionParams = {
|
||||
|
|
|
@ -23,9 +23,9 @@ export class Config {
|
|||
lruCapacity: null | number = null;
|
||||
displayInlayHints = true;
|
||||
maxInlayHintLength: null | number = null;
|
||||
excludeGlobs = [];
|
||||
excludeGlobs: string[] = [];
|
||||
useClientWatching = true;
|
||||
featureFlags = {};
|
||||
featureFlags: Record<string, boolean> = {};
|
||||
// for internal use
|
||||
withSysroot: null | boolean = null;
|
||||
cargoWatchOptions: CargoWatchOptions = {
|
||||
|
|
|
@ -69,7 +69,7 @@ interface Decoration {
|
|||
|
||||
// Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76
|
||||
function fancify(seed: string, shade: 'light' | 'dark') {
|
||||
const random = randomU32Numbers(hashString(seed))
|
||||
const random = randomU32Numbers(hashString(seed));
|
||||
const randomInt = (min: number, max: number) => {
|
||||
return Math.abs(random()) % (max - min + 1) + min;
|
||||
};
|
||||
|
@ -253,14 +253,14 @@ function randomU32Numbers(seed: number) {
|
|||
random ^= random >> 17;
|
||||
random ^= random << 5;
|
||||
random |= 0;
|
||||
return random
|
||||
}
|
||||
return random;
|
||||
};
|
||||
}
|
||||
|
||||
function hashString(str: string): number {
|
||||
let res = 0;
|
||||
for (let i = 0; i < str.length; ++i) {
|
||||
const c = str.codePointAt(i)!!;
|
||||
const c = str.codePointAt(i)!;
|
||||
res = (res * 31 + c) & ~0;
|
||||
}
|
||||
return res;
|
||||
|
|
|
@ -6,7 +6,7 @@ import { activateStatusDisplay } from './status_display';
|
|||
import { Ctx } from './ctx';
|
||||
import { activateHighlighting } from './highlighting';
|
||||
|
||||
let ctx!: Ctx;
|
||||
let ctx: Ctx | undefined;
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext) {
|
||||
ctx = new Ctx(context);
|
||||
|
|
Loading…
Reference in a new issue