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/commands/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index dc075aa82..4501809e2 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts @@ -21,7 +21,7 @@ function collectGarbage(ctx: Ctx): Cmd { function showReferences(ctx: Ctx): Cmd { return (uri: string, position: lc.Position, locations: lc.Location[]) => { - let client = ctx.client; + const client = ctx.client; if (client) { vscode.commands.executeCommand( 'editor.action.showReferences', -- cgit v1.2.3 From 81847524702dd7cb1eeae25a53444b325295b129 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 2 Feb 2020 21:37:22 +0200 Subject: vscode refactoring: use more laconic export snytax, split huge string to several lines --- editors/code/src/commands/index.ts | 45 ++++++++++++-------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 4501809e2..5a4c1df5e 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts @@ -4,22 +4,22 @@ import * as lc from 'vscode-languageclient'; import { Ctx, Cmd } from '../ctx'; import * as sourceChange from '../source_change'; -import { analyzerStatus } from './analyzer_status'; -import { matchingBrace } from './matching_brace'; -import { joinLines } from './join_lines'; -import { onEnter } from './on_enter'; -import { parentModule } from './parent_module'; -import { syntaxTree } from './syntax_tree'; -import { expandMacro } from './expand_macro'; -import { run, runSingle } from './runnables'; - -function collectGarbage(ctx: Ctx): Cmd { +export * from './analyzer_status'; +export * from './matching_brace'; +export * from './join_lines'; +export * from './on_enter'; +export * from './parent_module'; +export * from './syntax_tree'; +export * from './expand_macro'; +export * from './runnables'; + +export function collectGarbage(ctx: Ctx): Cmd { return async () => { ctx.client?.sendRequest('rust-analyzer/collectGarbage', null); }; } -function showReferences(ctx: Ctx): Cmd { +export function showReferences(ctx: Ctx): Cmd { return (uri: string, position: lc.Position, locations: lc.Location[]) => { const client = ctx.client; if (client) { @@ -33,13 +33,13 @@ function showReferences(ctx: Ctx): Cmd { }; } -function applySourceChange(ctx: Ctx): Cmd { +export function applySourceChange(ctx: Ctx): Cmd { return async (change: sourceChange.SourceChange) => { sourceChange.applySourceChange(ctx, change); }; } -function selectAndApplySourceChange(ctx: Ctx): Cmd { +export function selectAndApplySourceChange(ctx: Ctx): Cmd { return async (changes: sourceChange.SourceChange[]) => { if (changes.length === 1) { await sourceChange.applySourceChange(ctx, changes[0]); @@ -51,26 +51,9 @@ function selectAndApplySourceChange(ctx: Ctx): Cmd { }; } -function reload(ctx: Ctx): Cmd { +export function reload(ctx: Ctx): Cmd { return async () => { vscode.window.showInformationMessage('Reloading rust-analyzer...'); await ctx.restartServer(); }; } - -export { - analyzerStatus, - expandMacro, - joinLines, - matchingBrace, - parentModule, - syntaxTree, - onEnter, - collectGarbage, - run, - runSingle, - showReferences, - applySourceChange, - selectAndApplySourceChange, - reload -}; -- cgit v1.2.3 From 12d0970f7e4c4d7f91cccb12525fceea3c4c0669 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 2 Feb 2020 22:19:59 +0200 Subject: vscode extension: migrate from any to unknown where possible --- editors/code/src/commands/syntax_tree.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts index 02ea9f166..562df50cd 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 { // We need to order this after LS updates, but there's no API for that. // Hence, good old setTimeout. -function afterLs(f: () => any) { +function afterLs(f: () => unknown) { setTimeout(f, 10); } -- cgit v1.2.3 From 2fd7af2a62ce0c8acb5daa6b2c179b638318f31a Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 2 Feb 2020 23:23:01 +0200 Subject: vscode: use void where possible --- editors/code/src/commands/syntax_tree.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts index 562df50cd..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 { // We need to order this after LS updates, but there's no API for that. // Hence, good old setTimeout. -function afterLs(f: () => unknown) { +function afterLs(f: () => void) { setTimeout(f, 10); } -- cgit v1.2.3 From 23ef22dd4880606c4c3dc908d30c2cbeabc37f58 Mon Sep 17 00:00:00 2001 From: Gregoire Geis Date: Sun, 2 Feb 2020 02:21:04 +0100 Subject: Add regular onEnter command, allowing onEnter to be called without overriding the type command. --- editors/code/src/commands/on_enter.ts | 51 ++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 18 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts index 6f61883cd..1b3d3d741 100644 --- a/editors/code/src/commands/on_enter.ts +++ b/editors/code/src/commands/on_enter.ts @@ -1,28 +1,43 @@ +import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; import { applySourceChange, SourceChange } from '../source_change'; import { Cmd, Ctx } from '../ctx'; -export function onEnter(ctx: Ctx): Cmd { +async function handleKeypress(ctx: Ctx) { + const editor = ctx.activeRustEditor; + const client = ctx.client; + if (!editor) return false; + if (!client) return false; + + const request: lc.TextDocumentPositionParams = { + textDocument: { uri: editor.document.uri.toString() }, + position: client.code2ProtocolConverter.asPosition( + editor.selection.active, + ), + }; + const change = await client.sendRequest( + 'rust-analyzer/onEnter', + request, + ); + if (!change) return false; + + await applySourceChange(ctx, change); + return true; +} + +export function onEnterOverride(ctx: Ctx): Cmd { return async (event: { text: string }) => { - const editor = ctx.activeRustEditor; - const client = ctx.client; - if (!editor || event.text !== '\n') return false; - if (!client) return false; + if (event.text === '\n') { + handleKeypress(ctx); + } + }; +} - const request: lc.TextDocumentPositionParams = { - textDocument: { uri: editor.document.uri.toString() }, - position: client.code2ProtocolConverter.asPosition( - editor.selection.active, - ), - }; - const change = await client.sendRequest( - 'rust-analyzer/onEnter', - request, - ); - if (!change) return false; +export function onEnter(ctx: Ctx): Cmd { + return async () => { + if (handleKeypress(ctx)) return; - await applySourceChange(ctx, change); - return true; + await vscode.commands.executeCommand('default:type', { text: '\n' }); }; } -- cgit v1.2.3 From b70ad7e5f3d524204fab88fe2a8c5a6fbef9e88e Mon Sep 17 00:00:00 2001 From: Gregoire Geis Date: Mon, 3 Feb 2020 20:24:50 +0100 Subject: Remove enableEnhancedTyping and type overriding infrastructure. --- editors/code/src/commands/on_enter.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts index 1b3d3d741..ac582b423 100644 --- a/editors/code/src/commands/on_enter.ts +++ b/editors/code/src/commands/on_enter.ts @@ -26,17 +26,9 @@ async function handleKeypress(ctx: Ctx) { return true; } -export function onEnterOverride(ctx: Ctx): Cmd { - return async (event: { text: string }) => { - if (event.text === '\n') { - handleKeypress(ctx); - } - }; -} - export function onEnter(ctx: Ctx): Cmd { return async () => { - if (handleKeypress(ctx)) return; + if (await handleKeypress(ctx)) return; await vscode.commands.executeCommand('default:type', { text: '\n' }); }; -- cgit v1.2.3 From 875dc6d1a4973f70cd48b797ae755d1bd7a83fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Geis?= Date: Tue, 4 Feb 2020 01:44:12 +0100 Subject: Merge two if statements into one in editors/code/src/commands/on_enter.ts. Co-Authored-By: Veetaha --- editors/code/src/commands/on_enter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts index ac582b423..c636234da 100644 --- a/editors/code/src/commands/on_enter.ts +++ b/editors/code/src/commands/on_enter.ts @@ -8,7 +8,7 @@ async function handleKeypress(ctx: Ctx) { const editor = ctx.activeRustEditor; const client = ctx.client; if (!editor) return false; - if (!client) return false; + if (!editor || !client) return false; const request: lc.TextDocumentPositionParams = { textDocument: { uri: editor.document.uri.toString() }, -- 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/commands/on_enter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/commands') 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'; 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 = { -- 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/commands/index.ts | 2 +- editors/code/src/commands/syntax_tree.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 5a4c1df5e..aee969432 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts @@ -35,7 +35,7 @@ export function showReferences(ctx: Ctx): Cmd { export function applySourceChange(ctx: Ctx): Cmd { return async (change: sourceChange.SourceChange) => { - sourceChange.applySourceChange(ctx, change); + await sourceChange.applySourceChange(ctx, change); }; } diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts index 211f2251f..7dde66ad1 100644 --- a/editors/code/src/commands/syntax_tree.ts +++ b/editors/code/src/commands/syntax_tree.ts @@ -22,6 +22,7 @@ export function syntaxTree(ctx: Ctx): Cmd { if (doc.languageId !== 'rust') return; afterLs(() => tdcp.eventEmitter.fire(tdcp.uri)); }, + null, ctx.subscriptions, ); @@ -30,6 +31,7 @@ export function syntaxTree(ctx: Ctx): Cmd { if (!editor || editor.document.languageId !== 'rust') return; tdcp.eventEmitter.fire(tdcp.uri); }, + null, ctx.subscriptions, ); -- cgit v1.2.3