aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/client.ts29
-rw-r--r--editors/code/src/color_theme.ts18
-rw-r--r--editors/code/src/commands/on_enter.ts2
-rw-r--r--editors/code/src/config.ts4
-rw-r--r--editors/code/src/highlighting.ts8
-rw-r--r--editors/code/src/main.ts2
6 files changed, 29 insertions, 34 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 1778c4e9f..7e7e909dd 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -7,25 +7,21 @@ import { Config } from './config';
7 7
8export function createClient(config: Config): lc.LanguageClient { 8export function createClient(config: Config): lc.LanguageClient {
9 // '.' Is the fallback if no folder is open 9 // '.' 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. 10 // TODO?: Workspace folders support Uri's (eg: file://test.txt).
11 let folder: string = '.'; 11 // It might be a good idea to test if the uri points to a file.
12 if (workspace.workspaceFolders !== undefined) { 12 const workspaceFolderPath = workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.';
13 folder = workspace.workspaceFolders[0].uri.fsPath.toString();
14 }
15 13
16 const command = expandPathResolving(config.raLspServerPath); 14 const raLspServerPath = expandPathResolving(config.raLspServerPath);
17 if (spawnSync(command, ["--version"]).status !== 0) { 15 if (spawnSync(raLspServerPath, ["--version"]).status !== 0) {
18 window.showErrorMessage( 16 window.showErrorMessage(
19 `Unable to execute '${command} --version' 17 `Unable to execute '${raLspServerPath} --version'\n\n` +
20 18 `Perhaps it is not in $PATH?\n\n` +
21Perhaps it is not in $PATH? 19 `PATH=${process.env.PATH}\n`
22 20 );
23PATH=${process.env.PATH}
24`);
25 } 21 }
26 const run: lc.Executable = { 22 const run: lc.Executable = {
27 command, 23 command: raLspServerPath,
28 options: { cwd: folder }, 24 options: { cwd: workspaceFolderPath },
29 }; 25 };
30 const serverOptions: lc.ServerOptions = { 26 const serverOptions: lc.ServerOptions = {
31 run, 27 run,
@@ -43,8 +39,7 @@ PATH=${process.env.PATH}
43 cargoWatchEnable: config.cargoWatchOptions.enable, 39 cargoWatchEnable: config.cargoWatchOptions.enable,
44 cargoWatchArgs: config.cargoWatchOptions.arguments, 40 cargoWatchArgs: config.cargoWatchOptions.arguments,
45 cargoWatchCommand: config.cargoWatchOptions.command, 41 cargoWatchCommand: config.cargoWatchOptions.command,
46 cargoWatchAllTargets: 42 cargoWatchAllTargets: config.cargoWatchOptions.allTargets,
47 config.cargoWatchOptions.allTargets,
48 excludeGlobs: config.excludeGlobs, 43 excludeGlobs: config.excludeGlobs,
49 useClientWatching: config.useClientWatching, 44 useClientWatching: config.useClientWatching,
50 featureFlags: config.featureFlags, 45 featureFlags: config.featureFlags,
diff --git a/editors/code/src/color_theme.ts b/editors/code/src/color_theme.ts
index 7e10c7f79..a6957a76e 100644
--- a/editors/code/src/color_theme.ts
+++ b/editors/code/src/color_theme.ts
@@ -33,6 +33,7 @@ export class ColorTheme {
33 : typeof rule.scope === 'string' 33 : typeof rule.scope === 'string'
34 ? [rule.scope] 34 ? [rule.scope]
35 : rule.scope; 35 : rule.scope;
36
36 for (const scope of scopes) { 37 for (const scope of scopes) {
37 res.rules.set(scope, rule.settings); 38 res.rules.set(scope, rule.settings);
38 } 39 }
@@ -69,13 +70,13 @@ function loadThemeNamed(themeName: string): ColorTheme {
69 ); 70 );
70 } 71 }
71 72
72 const themePaths = vscode.extensions.all 73 const themePaths: string[] = vscode.extensions.all
73 .filter(isTheme) 74 .filter(isTheme)
74 .flatMap(ext => { 75 .flatMap(
75 return ext.packageJSON.contributes.themes 76 ext => ext.packageJSON.contributes.themes
76 .filter((it: any) => (it.id || it.label) === themeName) 77 .filter((it: any) => (it.id || it.label) === themeName)
77 .map((it: any) => path.join(ext.extensionPath, it.path)); 78 .map((it: any) => path.join(ext.extensionPath, it.path))
78 }); 79 );
79 80
80 const res = new ColorTheme(); 81 const res = new ColorTheme();
81 for (const themePath of themePaths) { 82 for (const themePath of themePaths) {
@@ -96,13 +97,12 @@ function loadThemeFile(themePath: string): ColorTheme {
96 return new ColorTheme(); 97 return new ColorTheme();
97 } 98 }
98 const obj = jsonc.parse(text); 99 const obj = jsonc.parse(text);
99 const tokenColors = obj?.tokenColors ?? []; 100 const tokenColors: TextMateRule[] = obj?.tokenColors ?? [];
100 const res = ColorTheme.fromRules(tokenColors); 101 const res = ColorTheme.fromRules(tokenColors);
101 102
102 for (const include in obj?.include ?? []) { 103 for (const include of obj?.include ?? []) {
103 const includePath = path.join(path.dirname(themePath), include); 104 const includePath = path.join(path.dirname(themePath), include);
104 const tmp = loadThemeFile(includePath); 105 res.mergeFrom(loadThemeFile(includePath));
105 res.mergeFrom(tmp);
106 } 106 }
107 107
108 return res; 108 return res;
diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts
index c636234da..25eaebcbe 100644
--- a/editors/code/src/commands/on_enter.ts
+++ b/editors/code/src/commands/on_enter.ts
@@ -7,7 +7,7 @@ import { Cmd, Ctx } from '../ctx';
7async function handleKeypress(ctx: Ctx) { 7async function handleKeypress(ctx: Ctx) {
8 const editor = ctx.activeRustEditor; 8 const editor = ctx.activeRustEditor;
9 const client = ctx.client; 9 const client = ctx.client;
10 if (!editor) return false; 10
11 if (!editor || !client) return false; 11 if (!editor || !client) return false;
12 12
13 const request: lc.TextDocumentPositionParams = { 13 const request: lc.TextDocumentPositionParams = {
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index fc21c8813..c750b2d5c 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -23,9 +23,9 @@ export class Config {
23 lruCapacity: null | number = null; 23 lruCapacity: null | number = null;
24 displayInlayHints = true; 24 displayInlayHints = true;
25 maxInlayHintLength: null | number = null; 25 maxInlayHintLength: null | number = null;
26 excludeGlobs = []; 26 excludeGlobs: string[] = [];
27 useClientWatching = true; 27 useClientWatching = true;
28 featureFlags = {}; 28 featureFlags: Record<string, boolean> = {};
29 // for internal use 29 // for internal use
30 withSysroot: null | boolean = null; 30 withSysroot: null | boolean = null;
31 cargoWatchOptions: CargoWatchOptions = { 31 cargoWatchOptions: CargoWatchOptions = {
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index 66216e0fc..e90fb8acc 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -69,7 +69,7 @@ interface Decoration {
69 69
70// Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76 70// Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76
71function fancify(seed: string, shade: 'light' | 'dark') { 71function fancify(seed: string, shade: 'light' | 'dark') {
72 const random = randomU32Numbers(hashString(seed)) 72 const random = randomU32Numbers(hashString(seed));
73 const randomInt = (min: number, max: number) => { 73 const randomInt = (min: number, max: number) => {
74 return Math.abs(random()) % (max - min + 1) + min; 74 return Math.abs(random()) % (max - min + 1) + min;
75 }; 75 };
@@ -253,14 +253,14 @@ function randomU32Numbers(seed: number) {
253 random ^= random >> 17; 253 random ^= random >> 17;
254 random ^= random << 5; 254 random ^= random << 5;
255 random |= 0; 255 random |= 0;
256 return random 256 return random;
257 } 257 };
258} 258}
259 259
260function hashString(str: string): number { 260function hashString(str: string): number {
261 let res = 0; 261 let res = 0;
262 for (let i = 0; i < str.length; ++i) { 262 for (let i = 0; i < str.length; ++i) {
263 const c = str.codePointAt(i)!!; 263 const c = str.codePointAt(i)!;
264 res = (res * 31 + c) & ~0; 264 res = (res * 31 + c) & ~0;
265 } 265 }
266 return res; 266 return res;
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index efc31b2e2..5efce41f4 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -6,7 +6,7 @@ import { activateStatusDisplay } from './status_display';
6import { Ctx } from './ctx'; 6import { Ctx } from './ctx';
7import { activateHighlighting } from './highlighting'; 7import { activateHighlighting } from './highlighting';
8 8
9let ctx!: Ctx; 9let ctx: Ctx | undefined;
10 10
11export async function activate(context: vscode.ExtensionContext) { 11export async function activate(context: vscode.ExtensionContext) {
12 ctx = new Ctx(context); 12 ctx = new Ctx(context);