From 5c39311f9639543fe1dd2a67ec5aff757bb830eb Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 1 Feb 2020 13:39:04 +0100 Subject: Fix seedrandom in packaged extension Fixes #2971 --- editors/code/src/highlighting.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'editors/code/src/highlighting.ts') diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index 014e96f75..fc7cd5a1c 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -1,7 +1,6 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; -import * as seedrandom_ from 'seedrandom'; -const seedrandom = seedrandom_; // https://github.com/jvandemo/generator-angular2-library/issues/221#issuecomment-355945207 +import seedrandom from 'seedrandom'; import { ColorTheme, TextMateRuleSettings } from './color_theme'; -- cgit v1.2.3 From 420462421d87a05c926501f8d4235f7660217924 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 2 Feb 2020 21:12:59 +0200 Subject: vscode extension cleanup: migrate to prefer-const tslint rule --- editors/code/src/highlighting.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'editors/code/src/highlighting.ts') diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index fc7cd5a1c..3d190c3ad 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -40,7 +40,7 @@ export function activateHighlighting(ctx: Ctx) { async (editor: vscode.TextEditor | undefined) => { if (!editor || editor.document.languageId !== 'rust') return; if (!ctx.config.highlightingOn) return; - let client = ctx.client; + const client = ctx.client; if (!client) return; const params: lc.TextDocumentIdentifier = { @@ -106,7 +106,7 @@ class Highlighter { } public setHighlights(editor: vscode.TextEditor, highlights: Decoration[]) { - let client = this.ctx.client; + const client = this.ctx.client; if (!client) return; // Initialize decorations if necessary // @@ -175,7 +175,7 @@ function initDecorations(): Map { const res = new Map(); TAG_TO_SCOPES.forEach((scopes, tag) => { if (!scopes) throw `unmapped tag: ${tag}`; - let rule = theme.lookup(scopes); + const rule = theme.lookup(scopes); const decor = createDecorationFromTextmate(rule); res.set(tag, decor); }); -- cgit v1.2.3 From ad57726f9181d7b80d217d7bf1b6cdca282d0982 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 3 Feb 2020 16:37:12 +0100 Subject: Use simple prng instead of a dependency closes #2999 --- editors/code/src/highlighting.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'editors/code/src/highlighting.ts') diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index 3d190c3ad..66216e0fc 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -1,6 +1,5 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; -import seedrandom from 'seedrandom'; import { ColorTheme, TextMateRuleSettings } from './color_theme'; @@ -70,9 +69,9 @@ interface Decoration { // Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76 function fancify(seed: string, shade: 'light' | 'dark') { - const random = seedrandom(seed); + const random = randomU32Numbers(hashString(seed)) const randomInt = (min: number, max: number) => { - return Math.floor(random() * (max - min + 1)) + min; + return Math.abs(random()) % (max - min + 1) + min; }; const h = randomInt(0, 360); @@ -246,3 +245,23 @@ const TAG_TO_SCOPES = new Map([ ["keyword.unsafe", ["keyword.other.unsafe"]], ["keyword.control", ["keyword.control"]], ]); + +function randomU32Numbers(seed: number) { + let random = seed | 0; + return () => { + random ^= random << 13; + random ^= random >> 17; + random ^= random << 5; + random |= 0; + return random + } +} + +function hashString(str: string): number { + let res = 0; + for (let i = 0; i < str.length; ++i) { + const c = str.codePointAt(i)!!; + res = (res * 31 + c) & ~0; + } + return res; +} -- cgit v1.2.3 From b89b22e43eb7e821674e0022f4061442b9e29394 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Wed, 5 Feb 2020 00:13:46 +0200 Subject: vscode: yet another refactor commit --- editors/code/src/highlighting.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'editors/code/src/highlighting.ts') 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 { // 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; -- cgit v1.2.3 From 8153b60e1d8abdcefbf6c7c9657f1ce65a216d7a Mon Sep 17 00:00:00 2001 From: Veetaha Date: Wed, 5 Feb 2020 22:39:47 +0200 Subject: vscode: eliminate floating promises and insane amount of resource handle leaks --- editors/code/src/highlighting.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'editors/code/src/highlighting.ts') diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index 66216e0fc..22458a391 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -32,6 +32,7 @@ export function activateHighlighting(ctx: Ctx) { vscode.workspace.onDidChangeConfiguration( _ => highlighter.removeHighlights(), + null, ctx.subscriptions, ); @@ -52,6 +53,7 @@ export function activateHighlighting(ctx: Ctx) { ); highlighter.setHighlights(editor, decorations); }, + null, ctx.subscriptions, ); } -- cgit v1.2.3