vscode refactoring: use more laconic export snytax, split huge string to several lines

This commit is contained in:
Veetaha 2020-02-02 21:37:22 +02:00
parent e72771ebc6
commit 8184752470
3 changed files with 17 additions and 32 deletions

View file

@ -4,22 +4,22 @@ import * as lc from 'vscode-languageclient';
import { Ctx, Cmd } from '../ctx'; import { Ctx, Cmd } from '../ctx';
import * as sourceChange from '../source_change'; import * as sourceChange from '../source_change';
import { analyzerStatus } from './analyzer_status'; export * from './analyzer_status';
import { matchingBrace } from './matching_brace'; export * from './matching_brace';
import { joinLines } from './join_lines'; export * from './join_lines';
import { onEnter } from './on_enter'; export * from './on_enter';
import { parentModule } from './parent_module'; export * from './parent_module';
import { syntaxTree } from './syntax_tree'; export * from './syntax_tree';
import { expandMacro } from './expand_macro'; export * from './expand_macro';
import { run, runSingle } from './runnables'; export * from './runnables';
function collectGarbage(ctx: Ctx): Cmd { export function collectGarbage(ctx: Ctx): Cmd {
return async () => { return async () => {
ctx.client?.sendRequest<null>('rust-analyzer/collectGarbage', null); ctx.client?.sendRequest<null>('rust-analyzer/collectGarbage', null);
}; };
} }
function showReferences(ctx: Ctx): Cmd { export function showReferences(ctx: Ctx): Cmd {
return (uri: string, position: lc.Position, locations: lc.Location[]) => { return (uri: string, position: lc.Position, locations: lc.Location[]) => {
const client = ctx.client; const client = ctx.client;
if (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) => { return async (change: sourceChange.SourceChange) => {
sourceChange.applySourceChange(ctx, change); sourceChange.applySourceChange(ctx, change);
}; };
} }
function selectAndApplySourceChange(ctx: Ctx): Cmd { export function selectAndApplySourceChange(ctx: Ctx): Cmd {
return async (changes: sourceChange.SourceChange[]) => { return async (changes: sourceChange.SourceChange[]) => {
if (changes.length === 1) { if (changes.length === 1) {
await sourceChange.applySourceChange(ctx, changes[0]); 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 () => { return async () => {
vscode.window.showInformationMessage('Reloading rust-analyzer...'); vscode.window.showInformationMessage('Reloading rust-analyzer...');
await ctx.restartServer(); await ctx.restartServer();
}; };
} }
export {
analyzerStatus,
expandMacro,
joinLines,
matchingBrace,
parentModule,
syntaxTree,
onEnter,
collectGarbage,
run,
runSingle,
showReferences,
applySourceChange,
selectAndApplySourceChange,
reload
};

View file

@ -66,7 +66,9 @@ export class Ctx {
this.pushCleanup(d); this.pushCleanup(d);
} catch (_) { } catch (_) {
vscode.window.showWarningMessage( vscode.window.showWarningMessage(
'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', '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',
); );
} }
} }

View file

@ -11,7 +11,7 @@ let ctx!: Ctx;
export async function activate(context: vscode.ExtensionContext) { export async function activate(context: vscode.ExtensionContext) {
ctx = new Ctx(context); ctx = new Ctx(context);
// Commands which invokes manually via command pallet, shortcut, etc. // Commands which invokes manually via command pallete, shortcut, etc.
ctx.registerCommand('analyzerStatus', commands.analyzerStatus); ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
ctx.registerCommand('collectGarbage', commands.collectGarbage); ctx.registerCommand('collectGarbage', commands.collectGarbage);
ctx.registerCommand('matchingBrace', commands.matchingBrace); ctx.registerCommand('matchingBrace', commands.matchingBrace);