diff options
Diffstat (limited to 'editors/code/src')
-rw-r--r-- | editors/code/src/client.ts | 2 | ||||
-rw-r--r-- | editors/code/src/color_theme.ts | 4 | ||||
-rw-r--r-- | editors/code/src/commands/index.ts | 47 | ||||
-rw-r--r-- | editors/code/src/commands/syntax_tree.ts | 2 | ||||
-rw-r--r-- | editors/code/src/ctx.ts | 22 | ||||
-rw-r--r-- | editors/code/src/highlighting.ts | 31 | ||||
-rw-r--r-- | editors/code/src/inlay_hints.ts | 6 | ||||
-rw-r--r-- | editors/code/src/main.ts | 2 | ||||
-rw-r--r-- | editors/code/src/status_display.ts | 4 |
9 files changed, 64 insertions, 56 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 15e1a0873..1778c4e9f 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts | |||
@@ -68,7 +68,7 @@ PATH=${process.env.PATH} | |||
68 | // This also requires considering our settings strategy, which is work which needs doing | 68 | // This also requires considering our settings strategy, which is work which needs doing |
69 | // @ts-ignore The tracer is private to vscode-languageclient, but we need access to it to not log publishDecorations requests | 69 | // @ts-ignore The tracer is private to vscode-languageclient, but we need access to it to not log publishDecorations requests |
70 | res._tracer = { | 70 | res._tracer = { |
71 | log: (messageOrDataObject: string | any, data?: string) => { | 71 | log: (messageOrDataObject: string | unknown, data?: string) => { |
72 | if (typeof messageOrDataObject === 'string') { | 72 | if (typeof messageOrDataObject === 'string') { |
73 | if ( | 73 | if ( |
74 | messageOrDataObject.includes( | 74 | messageOrDataObject.includes( |
diff --git a/editors/code/src/color_theme.ts b/editors/code/src/color_theme.ts index d816f617d..7e10c7f79 100644 --- a/editors/code/src/color_theme.ts +++ b/editors/code/src/color_theme.ts | |||
@@ -61,7 +61,7 @@ export class ColorTheme { | |||
61 | } | 61 | } |
62 | 62 | ||
63 | function loadThemeNamed(themeName: string): ColorTheme { | 63 | function loadThemeNamed(themeName: string): ColorTheme { |
64 | function isTheme(extension: vscode.Extension<any>): boolean { | 64 | function isTheme(extension: vscode.Extension<unknown>): boolean { |
65 | return ( | 65 | return ( |
66 | extension.extensionKind === vscode.ExtensionKind.UI && | 66 | extension.extensionKind === vscode.ExtensionKind.UI && |
67 | extension.packageJSON.contributes && | 67 | extension.packageJSON.contributes && |
@@ -69,7 +69,7 @@ function loadThemeNamed(themeName: string): ColorTheme { | |||
69 | ); | 69 | ); |
70 | } | 70 | } |
71 | 71 | ||
72 | let themePaths = vscode.extensions.all | 72 | const themePaths = vscode.extensions.all |
73 | .filter(isTheme) | 73 | .filter(isTheme) |
74 | .flatMap(ext => { | 74 | .flatMap(ext => { |
75 | return ext.packageJSON.contributes.themes | 75 | return ext.packageJSON.contributes.themes |
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index dc075aa82..5a4c1df5e 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts | |||
@@ -4,24 +4,24 @@ import * as lc from 'vscode-languageclient'; | |||
4 | import { Ctx, Cmd } from '../ctx'; | 4 | import { Ctx, Cmd } from '../ctx'; |
5 | import * as sourceChange from '../source_change'; | 5 | import * as sourceChange from '../source_change'; |
6 | 6 | ||
7 | import { analyzerStatus } from './analyzer_status'; | 7 | export * from './analyzer_status'; |
8 | import { matchingBrace } from './matching_brace'; | 8 | export * from './matching_brace'; |
9 | import { joinLines } from './join_lines'; | 9 | export * from './join_lines'; |
10 | import { onEnter } from './on_enter'; | 10 | export * from './on_enter'; |
11 | import { parentModule } from './parent_module'; | 11 | export * from './parent_module'; |
12 | import { syntaxTree } from './syntax_tree'; | 12 | export * from './syntax_tree'; |
13 | import { expandMacro } from './expand_macro'; | 13 | export * from './expand_macro'; |
14 | import { run, runSingle } from './runnables'; | 14 | export * from './runnables'; |
15 | 15 | ||
16 | function collectGarbage(ctx: Ctx): Cmd { | 16 | export function collectGarbage(ctx: Ctx): Cmd { |
17 | return async () => { | 17 | return async () => { |
18 | ctx.client?.sendRequest<null>('rust-analyzer/collectGarbage', null); | 18 | ctx.client?.sendRequest<null>('rust-analyzer/collectGarbage', null); |
19 | }; | 19 | }; |
20 | } | 20 | } |
21 | 21 | ||
22 | function showReferences(ctx: Ctx): Cmd { | 22 | export function showReferences(ctx: Ctx): Cmd { |
23 | return (uri: string, position: lc.Position, locations: lc.Location[]) => { | 23 | return (uri: string, position: lc.Position, locations: lc.Location[]) => { |
24 | let client = ctx.client; | 24 | const client = ctx.client; |
25 | if (client) { | 25 | if (client) { |
26 | vscode.commands.executeCommand( | 26 | vscode.commands.executeCommand( |
27 | 'editor.action.showReferences', | 27 | 'editor.action.showReferences', |
@@ -33,13 +33,13 @@ function showReferences(ctx: Ctx): Cmd { | |||
33 | }; | 33 | }; |
34 | } | 34 | } |
35 | 35 | ||
36 | function applySourceChange(ctx: Ctx): Cmd { | 36 | export function applySourceChange(ctx: Ctx): Cmd { |
37 | return async (change: sourceChange.SourceChange) => { | 37 | return async (change: sourceChange.SourceChange) => { |
38 | sourceChange.applySourceChange(ctx, change); | 38 | sourceChange.applySourceChange(ctx, change); |
39 | }; | 39 | }; |
40 | } | 40 | } |
41 | 41 | ||
42 | function selectAndApplySourceChange(ctx: Ctx): Cmd { | 42 | export function selectAndApplySourceChange(ctx: Ctx): Cmd { |
43 | return async (changes: sourceChange.SourceChange[]) => { | 43 | return async (changes: sourceChange.SourceChange[]) => { |
44 | if (changes.length === 1) { | 44 | if (changes.length === 1) { |
45 | await sourceChange.applySourceChange(ctx, changes[0]); | 45 | await sourceChange.applySourceChange(ctx, changes[0]); |
@@ -51,26 +51,9 @@ function selectAndApplySourceChange(ctx: Ctx): Cmd { | |||
51 | }; | 51 | }; |
52 | } | 52 | } |
53 | 53 | ||
54 | function reload(ctx: Ctx): Cmd { | 54 | export function reload(ctx: Ctx): Cmd { |
55 | return async () => { | 55 | return async () => { |
56 | vscode.window.showInformationMessage('Reloading rust-analyzer...'); | 56 | vscode.window.showInformationMessage('Reloading rust-analyzer...'); |
57 | await ctx.restartServer(); | 57 | await ctx.restartServer(); |
58 | }; | 58 | }; |
59 | } | 59 | } |
60 | |||
61 | export { | ||
62 | analyzerStatus, | ||
63 | expandMacro, | ||
64 | joinLines, | ||
65 | matchingBrace, | ||
66 | parentModule, | ||
67 | syntaxTree, | ||
68 | onEnter, | ||
69 | collectGarbage, | ||
70 | run, | ||
71 | runSingle, | ||
72 | showReferences, | ||
73 | applySourceChange, | ||
74 | selectAndApplySourceChange, | ||
75 | reload | ||
76 | }; | ||
diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts index 02ea9f166..211f2251f 100644 --- a/editors/code/src/commands/syntax_tree.ts +++ b/editors/code/src/commands/syntax_tree.ts | |||
@@ -55,7 +55,7 @@ export function syntaxTree(ctx: Ctx): Cmd { | |||
55 | 55 | ||
56 | // We need to order this after LS updates, but there's no API for that. | 56 | // We need to order this after LS updates, but there's no API for that. |
57 | // Hence, good old setTimeout. | 57 | // Hence, good old setTimeout. |
58 | function afterLs(f: () => any) { | 58 | function afterLs(f: () => void) { |
59 | setTimeout(f, 10); | 59 | setTimeout(f, 10); |
60 | } | 60 | } |
61 | 61 | ||
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index a2a4e42a9..05d21ae56 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | |||
3 | import { Config } from './config'; | 4 | import { Config } from './config'; |
4 | import { createClient } from './client'; | 5 | import { createClient } from './client'; |
5 | 6 | ||
@@ -20,7 +21,7 @@ export class Ctx { | |||
20 | } | 21 | } |
21 | 22 | ||
22 | async restartServer() { | 23 | async restartServer() { |
23 | let old = this.client; | 24 | const old = this.client; |
24 | if (old) { | 25 | if (old) { |
25 | await old.stop(); | 26 | await old.stop(); |
26 | } | 27 | } |
@@ -52,12 +53,12 @@ export class Ctx { | |||
52 | overrideCommand(name: string, factory: (ctx: Ctx) => Cmd) { | 53 | overrideCommand(name: string, factory: (ctx: Ctx) => Cmd) { |
53 | const defaultCmd = `default:${name}`; | 54 | const defaultCmd = `default:${name}`; |
54 | const override = factory(this); | 55 | const override = factory(this); |
55 | const original = (...args: any[]) => | 56 | const original = (...args: unknown[]) => |
56 | vscode.commands.executeCommand(defaultCmd, ...args); | 57 | vscode.commands.executeCommand(defaultCmd, ...args); |
57 | try { | 58 | try { |
58 | const d = vscode.commands.registerCommand( | 59 | const d = vscode.commands.registerCommand( |
59 | name, | 60 | name, |
60 | async (...args: any[]) => { | 61 | async (...args: unknown[]) => { |
61 | if (!(await override(...args))) { | 62 | if (!(await override(...args))) { |
62 | return await original(...args); | 63 | return await original(...args); |
63 | } | 64 | } |
@@ -66,16 +67,18 @@ export class Ctx { | |||
66 | this.pushCleanup(d); | 67 | this.pushCleanup(d); |
67 | } catch (_) { | 68 | } catch (_) { |
68 | vscode.window.showWarningMessage( | 69 | vscode.window.showWarningMessage( |
69 | 'Enhanced typing feature is disabled because of incompatibility with VIM extension, consider turning off rust-analyzer.enableEnhancedTyping: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/README.md#settings', | 70 | 'Enhanced typing feature is disabled because of incompatibility ' + |
71 | 'with VIM extension, consider turning off rust-analyzer.enableEnhancedTyping: ' + | ||
72 | 'https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/README.md#settings', | ||
70 | ); | 73 | ); |
71 | } | 74 | } |
72 | } | 75 | } |
73 | 76 | ||
74 | get subscriptions(): { dispose(): any }[] { | 77 | get subscriptions(): Disposable[] { |
75 | return this.extCtx.subscriptions; | 78 | return this.extCtx.subscriptions; |
76 | } | 79 | } |
77 | 80 | ||
78 | pushCleanup(d: { dispose(): any }) { | 81 | pushCleanup(d: Disposable) { |
79 | this.extCtx.subscriptions.push(d); | 82 | this.extCtx.subscriptions.push(d); |
80 | } | 83 | } |
81 | 84 | ||
@@ -84,12 +87,15 @@ export class Ctx { | |||
84 | } | 87 | } |
85 | } | 88 | } |
86 | 89 | ||
87 | export type Cmd = (...args: any[]) => any; | 90 | export interface Disposable { |
91 | dispose(): void; | ||
92 | } | ||
93 | export type Cmd = (...args: any[]) => unknown; | ||
88 | 94 | ||
89 | export async function sendRequestWithRetry<R>( | 95 | export async function sendRequestWithRetry<R>( |
90 | client: lc.LanguageClient, | 96 | client: lc.LanguageClient, |
91 | method: string, | 97 | method: string, |
92 | param: any, | 98 | param: unknown, |
93 | token?: vscode.CancellationToken, | 99 | token?: vscode.CancellationToken, |
94 | ): Promise<R> { | 100 | ): Promise<R> { |
95 | for (const delay of [2, 4, 6, 8, 10, null]) { | 101 | for (const delay of [2, 4, 6, 8, 10, null]) { |
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index fc7cd5a1c..66216e0fc 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | import seedrandom from 'seedrandom'; | ||
4 | 3 | ||
5 | import { ColorTheme, TextMateRuleSettings } from './color_theme'; | 4 | import { ColorTheme, TextMateRuleSettings } from './color_theme'; |
6 | 5 | ||
@@ -40,7 +39,7 @@ export function activateHighlighting(ctx: Ctx) { | |||
40 | async (editor: vscode.TextEditor | undefined) => { | 39 | async (editor: vscode.TextEditor | undefined) => { |
41 | if (!editor || editor.document.languageId !== 'rust') return; | 40 | if (!editor || editor.document.languageId !== 'rust') return; |
42 | if (!ctx.config.highlightingOn) return; | 41 | if (!ctx.config.highlightingOn) return; |
43 | let client = ctx.client; | 42 | const client = ctx.client; |
44 | if (!client) return; | 43 | if (!client) return; |
45 | 44 | ||
46 | const params: lc.TextDocumentIdentifier = { | 45 | const params: lc.TextDocumentIdentifier = { |
@@ -70,9 +69,9 @@ interface Decoration { | |||
70 | 69 | ||
71 | // 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 |
72 | function fancify(seed: string, shade: 'light' | 'dark') { | 71 | function fancify(seed: string, shade: 'light' | 'dark') { |
73 | const random = seedrandom(seed); | 72 | const random = randomU32Numbers(hashString(seed)) |
74 | const randomInt = (min: number, max: number) => { | 73 | const randomInt = (min: number, max: number) => { |
75 | return Math.floor(random() * (max - min + 1)) + min; | 74 | return Math.abs(random()) % (max - min + 1) + min; |
76 | }; | 75 | }; |
77 | 76 | ||
78 | const h = randomInt(0, 360); | 77 | const h = randomInt(0, 360); |
@@ -106,7 +105,7 @@ class Highlighter { | |||
106 | } | 105 | } |
107 | 106 | ||
108 | public setHighlights(editor: vscode.TextEditor, highlights: Decoration[]) { | 107 | public setHighlights(editor: vscode.TextEditor, highlights: Decoration[]) { |
109 | let client = this.ctx.client; | 108 | const client = this.ctx.client; |
110 | if (!client) return; | 109 | if (!client) return; |
111 | // Initialize decorations if necessary | 110 | // Initialize decorations if necessary |
112 | // | 111 | // |
@@ -175,7 +174,7 @@ function initDecorations(): Map<string, vscode.TextEditorDecorationType> { | |||
175 | const res = new Map(); | 174 | const res = new Map(); |
176 | TAG_TO_SCOPES.forEach((scopes, tag) => { | 175 | TAG_TO_SCOPES.forEach((scopes, tag) => { |
177 | if (!scopes) throw `unmapped tag: ${tag}`; | 176 | if (!scopes) throw `unmapped tag: ${tag}`; |
178 | let rule = theme.lookup(scopes); | 177 | const rule = theme.lookup(scopes); |
179 | const decor = createDecorationFromTextmate(rule); | 178 | const decor = createDecorationFromTextmate(rule); |
180 | res.set(tag, decor); | 179 | res.set(tag, decor); |
181 | }); | 180 | }); |
@@ -246,3 +245,23 @@ const TAG_TO_SCOPES = new Map<string, string[]>([ | |||
246 | ["keyword.unsafe", ["keyword.other.unsafe"]], | 245 | ["keyword.unsafe", ["keyword.other.unsafe"]], |
247 | ["keyword.control", ["keyword.control"]], | 246 | ["keyword.control", ["keyword.control"]], |
248 | ]); | 247 | ]); |
248 | |||
249 | function randomU32Numbers(seed: number) { | ||
250 | let random = seed | 0; | ||
251 | return () => { | ||
252 | random ^= random << 13; | ||
253 | random ^= random >> 17; | ||
254 | random ^= random << 5; | ||
255 | random |= 0; | ||
256 | return random | ||
257 | } | ||
258 | } | ||
259 | |||
260 | function hashString(str: string): number { | ||
261 | let res = 0; | ||
262 | for (let i = 0; i < str.length; ++i) { | ||
263 | const c = str.codePointAt(i)!!; | ||
264 | res = (res * 31 + c) & ~0; | ||
265 | } | ||
266 | return res; | ||
267 | } | ||
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index 6357e44f1..ae7510183 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts | |||
@@ -127,13 +127,13 @@ class HintsUpdater { | |||
127 | } | 127 | } |
128 | 128 | ||
129 | private async queryHints(documentUri: string): Promise<InlayHint[] | null> { | 129 | private async queryHints(documentUri: string): Promise<InlayHint[] | null> { |
130 | let client = this.ctx.client; | 130 | const client = this.ctx.client; |
131 | if (!client) return null; | 131 | if (!client) return null; |
132 | const request: InlayHintsParams = { | 132 | const request: InlayHintsParams = { |
133 | textDocument: { uri: documentUri }, | 133 | textDocument: { uri: documentUri }, |
134 | }; | 134 | }; |
135 | let tokenSource = new vscode.CancellationTokenSource(); | 135 | const tokenSource = new vscode.CancellationTokenSource(); |
136 | let prev = this.pending.get(documentUri); | 136 | const prev = this.pending.get(documentUri); |
137 | if (prev) prev.cancel(); | 137 | if (prev) prev.cancel(); |
138 | this.pending.set(documentUri, tokenSource); | 138 | this.pending.set(documentUri, tokenSource); |
139 | try { | 139 | try { |
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 0494ccf63..6813c3c4c 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -11,7 +11,7 @@ let ctx!: Ctx; | |||
11 | export async function activate(context: vscode.ExtensionContext) { | 11 | export async function activate(context: vscode.ExtensionContext) { |
12 | ctx = new Ctx(context); | 12 | ctx = new Ctx(context); |
13 | 13 | ||
14 | // Commands which invokes manually via command pallet, shortcut, etc. | 14 | // Commands which invokes manually via command palette, shortcut, etc. |
15 | ctx.registerCommand('analyzerStatus', commands.analyzerStatus); | 15 | ctx.registerCommand('analyzerStatus', commands.analyzerStatus); |
16 | ctx.registerCommand('collectGarbage', commands.collectGarbage); | 16 | ctx.registerCommand('collectGarbage', commands.collectGarbage); |
17 | ctx.registerCommand('matchingBrace', commands.matchingBrace); | 17 | ctx.registerCommand('matchingBrace', commands.matchingBrace); |
diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts index 7345bc3f5..4317410c7 100644 --- a/editors/code/src/status_display.ts +++ b/editors/code/src/status_display.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | 2 | ||
3 | import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd } from 'vscode-languageclient'; | 3 | import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd, Disposable } from 'vscode-languageclient'; |
4 | 4 | ||
5 | import { Ctx } from './ctx'; | 5 | import { Ctx } from './ctx'; |
6 | 6 | ||
@@ -14,7 +14,7 @@ export function activateStatusDisplay(ctx: Ctx) { | |||
14 | }); | 14 | }); |
15 | } | 15 | } |
16 | 16 | ||
17 | class StatusDisplay implements vscode.Disposable { | 17 | class StatusDisplay implements vscode.Disposable, Disposable { |
18 | packageName?: string; | 18 | packageName?: string; |
19 | 19 | ||
20 | private i: number = 0; | 20 | private i: number = 0; |