Skip to content

Commit 2471b6b

Browse files
bors[bot]Veetaha
andauthored
Merge #3015
3015: vscode: yet another refactor commit r=matklad a=Veetaha It compiles, it runs in dev extension host, It bundles, it runs when bundled and installed. Removed 5 lines of code as you like less code, especially TypeScript code) Co-authored-by: Veetaha <gerzoh1@gmail.com>
2 parents 8d0f7da + 49a6814 commit 2471b6b

File tree

6 files changed

+29
-34
lines changed

6 files changed

+29
-34
lines changed

editors/code/src/client.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@ import { Config } from './config';
77

88
export function createClient(config: Config): lc.LanguageClient {
99
// '.' Is the fallback if no folder is open
10-
// 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.
11-
let folder: string = '.';
12-
if (workspace.workspaceFolders !== undefined) {
13-
folder = workspace.workspaceFolders[0].uri.fsPath.toString();
14-
}
10+
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
11+
// It might be a good idea to test if the uri points to a file.
12+
const workspaceFolderPath = workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.';
1513

16-
const command = expandPathResolving(config.raLspServerPath);
17-
if (spawnSync(command, ["--version"]).status !== 0) {
14+
const raLspServerPath = expandPathResolving(config.raLspServerPath);
15+
if (spawnSync(raLspServerPath, ["--version"]).status !== 0) {
1816
window.showErrorMessage(
19-
`Unable to execute '${command} --version'
20-
21-
Perhaps it is not in $PATH?
22-
23-
PATH=${process.env.PATH}
24-
`);
17+
`Unable to execute '${raLspServerPath} --version'\n\n` +
18+
`Perhaps it is not in $PATH?\n\n` +
19+
`PATH=${process.env.PATH}\n`
20+
);
2521
}
2622
const run: lc.Executable = {
27-
command,
28-
options: { cwd: folder },
23+
command: raLspServerPath,
24+
options: { cwd: workspaceFolderPath },
2925
};
3026
const serverOptions: lc.ServerOptions = {
3127
run,
@@ -43,8 +39,7 @@ PATH=${process.env.PATH}
4339
cargoWatchEnable: config.cargoWatchOptions.enable,
4440
cargoWatchArgs: config.cargoWatchOptions.arguments,
4541
cargoWatchCommand: config.cargoWatchOptions.command,
46-
cargoWatchAllTargets:
47-
config.cargoWatchOptions.allTargets,
42+
cargoWatchAllTargets: config.cargoWatchOptions.allTargets,
4843
excludeGlobs: config.excludeGlobs,
4944
useClientWatching: config.useClientWatching,
5045
featureFlags: config.featureFlags,

editors/code/src/color_theme.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class ColorTheme {
3333
: typeof rule.scope === 'string'
3434
? [rule.scope]
3535
: rule.scope;
36+
3637
for (const scope of scopes) {
3738
res.rules.set(scope, rule.settings);
3839
}
@@ -69,13 +70,13 @@ function loadThemeNamed(themeName: string): ColorTheme {
6970
);
7071
}
7172

72-
const themePaths = vscode.extensions.all
73+
const themePaths: string[] = vscode.extensions.all
7374
.filter(isTheme)
74-
.flatMap(ext => {
75-
return ext.packageJSON.contributes.themes
75+
.flatMap(
76+
ext => ext.packageJSON.contributes.themes
7677
.filter((it: any) => (it.id || it.label) === themeName)
77-
.map((it: any) => path.join(ext.extensionPath, it.path));
78-
});
78+
.map((it: any) => path.join(ext.extensionPath, it.path))
79+
);
7980

8081
const res = new ColorTheme();
8182
for (const themePath of themePaths) {
@@ -96,13 +97,12 @@ function loadThemeFile(themePath: string): ColorTheme {
9697
return new ColorTheme();
9798
}
9899
const obj = jsonc.parse(text);
99-
const tokenColors = obj?.tokenColors ?? [];
100+
const tokenColors: TextMateRule[] = obj?.tokenColors ?? [];
100101
const res = ColorTheme.fromRules(tokenColors);
101102

102-
for (const include in obj?.include ?? []) {
103+
for (const include of obj?.include ?? []) {
103104
const includePath = path.join(path.dirname(themePath), include);
104-
const tmp = loadThemeFile(includePath);
105-
res.mergeFrom(tmp);
105+
res.mergeFrom(loadThemeFile(includePath));
106106
}
107107

108108
return res;

editors/code/src/commands/on_enter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Cmd, Ctx } from '../ctx';
77
async function handleKeypress(ctx: Ctx) {
88
const editor = ctx.activeRustEditor;
99
const client = ctx.client;
10-
if (!editor) return false;
10+
1111
if (!editor || !client) return false;
1212

1313
const request: lc.TextDocumentPositionParams = {

editors/code/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export class Config {
2323
lruCapacity: null | number = null;
2424
displayInlayHints = true;
2525
maxInlayHintLength: null | number = null;
26-
excludeGlobs = [];
26+
excludeGlobs: string[] = [];
2727
useClientWatching = true;
28-
featureFlags = {};
28+
featureFlags: Record<string, boolean> = {};
2929
// for internal use
3030
withSysroot: null | boolean = null;
3131
cargoWatchOptions: CargoWatchOptions = {

editors/code/src/highlighting.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ interface Decoration {
6969

7070
// Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76
7171
function fancify(seed: string, shade: 'light' | 'dark') {
72-
const random = randomU32Numbers(hashString(seed))
72+
const random = randomU32Numbers(hashString(seed));
7373
const randomInt = (min: number, max: number) => {
7474
return Math.abs(random()) % (max - min + 1) + min;
7575
};
@@ -253,14 +253,14 @@ function randomU32Numbers(seed: number) {
253253
random ^= random >> 17;
254254
random ^= random << 5;
255255
random |= 0;
256-
return random
257-
}
256+
return random;
257+
};
258258
}
259259

260260
function hashString(str: string): number {
261261
let res = 0;
262262
for (let i = 0; i < str.length; ++i) {
263-
const c = str.codePointAt(i)!!;
263+
const c = str.codePointAt(i)!;
264264
res = (res * 31 + c) & ~0;
265265
}
266266
return res;

editors/code/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { activateStatusDisplay } from './status_display';
66
import { Ctx } from './ctx';
77
import { activateHighlighting } from './highlighting';
88

9-
let ctx!: Ctx;
9+
let ctx: Ctx | undefined;
1010

1111
export async function activate(context: vscode.ExtensionContext) {
1212
ctx = new Ctx(context);

0 commit comments

Comments
 (0)