diff options
| author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2019-12-31 18:50:32 +0100 |
|---|---|---|
| committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2019-12-31 18:50:32 +0100 |
| commit | cb41ffbbbdea66d3a0abae4d270da1224a5de91c (patch) | |
| tree | 40582f9bb4331676a0a469b728a5e6cfe1df5300 /editors/code | |
| parent | 6368b40dd98b208da3758d4d1eed34cf276e3b09 (diff) | |
| download | rust-cb41ffbbbdea66d3a0abae4d270da1224a5de91c.tar.gz rust-cb41ffbbbdea66d3a0abae4d270da1224a5de91c.zip | |
Fix NPEs
Diffstat (limited to 'editors/code')
| -rw-r--r-- | editors/code/src/commands/matching_brace.ts | 12 | ||||
| -rw-r--r-- | editors/code/src/commands/on_enter.ts | 6 | ||||
| -rw-r--r-- | editors/code/src/commands/parent_module.ts | 11 | ||||
| -rw-r--r-- | editors/code/src/commands/runnables.ts | 7 | ||||
| -rw-r--r-- | editors/code/src/commands/syntax_tree.ts | 9 |
5 files changed, 24 insertions, 21 deletions
diff --git a/editors/code/src/commands/matching_brace.ts b/editors/code/src/commands/matching_brace.ts index 59c253f8866..7c58bb7e720 100644 --- a/editors/code/src/commands/matching_brace.ts +++ b/editors/code/src/commands/matching_brace.ts @@ -6,21 +6,21 @@ import { Ctx, Cmd } from '../ctx'; export function matchingBrace(ctx: Ctx): Cmd { return async () => { const editor = ctx.activeRustEditor; - if (!editor) { - return; - } + const client = ctx.client; + if (!editor || !client) return; + const request: FindMatchingBraceParams = { textDocument: { uri: editor.document.uri.toString() }, offsets: editor.selections.map(s => - ctx.client.code2ProtocolConverter.asPosition(s.active), + client.code2ProtocolConverter.asPosition(s.active), ), }; - const response = await ctx.client.sendRequest<lc.Position[]>( + const response = await client.sendRequest<lc.Position[]>( 'rust-analyzer/findMatchingBrace', request, ); editor.selections = editor.selections.map((sel, idx) => { - const active = ctx.client.protocol2CodeConverter.asPosition( + const active = client.protocol2CodeConverter.asPosition( response[idx], ); const anchor = sel.isEmpty ? active : sel.anchor; diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts index 8324060e88e..6f61883cddb 100644 --- a/editors/code/src/commands/on_enter.ts +++ b/editors/code/src/commands/on_enter.ts @@ -6,15 +6,17 @@ import { Cmd, Ctx } from '../ctx'; export function onEnter(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; const request: lc.TextDocumentPositionParams = { textDocument: { uri: editor.document.uri.toString() }, - position: ctx.client.code2ProtocolConverter.asPosition( + position: client.code2ProtocolConverter.asPosition( editor.selection.active, ), }; - const change = await ctx.client.sendRequest<undefined | SourceChange>( + const change = await client.sendRequest<undefined | SourceChange>( 'rust-analyzer/onEnter', request, ); diff --git a/editors/code/src/commands/parent_module.ts b/editors/code/src/commands/parent_module.ts index 258b61b21fe..bf40b402185 100644 --- a/editors/code/src/commands/parent_module.ts +++ b/editors/code/src/commands/parent_module.ts @@ -6,23 +6,24 @@ import { Ctx, Cmd } from '../ctx'; export function parentModule(ctx: Ctx): Cmd { return async () => { const editor = ctx.activeRustEditor; - if (!editor) return; + const client = ctx.client; + if (!editor || !client) return; const request: lc.TextDocumentPositionParams = { textDocument: { uri: editor.document.uri.toString() }, - position: ctx.client.code2ProtocolConverter.asPosition( + position: client.code2ProtocolConverter.asPosition( editor.selection.active, ), }; - const response = await ctx.client.sendRequest<lc.Location[]>( + const response = await client.sendRequest<lc.Location[]>( 'rust-analyzer/parentModule', request, ); const loc = response[0]; if (loc == null) return; - const uri = ctx.client.protocol2CodeConverter.asUri(loc.uri); - const range = ctx.client.protocol2CodeConverter.asRange(loc.range); + const uri = client.protocol2CodeConverter.asUri(loc.uri); + const range = client.protocol2CodeConverter.asRange(loc.range); const doc = await vscode.workspace.openTextDocument(uri); const e = await vscode.window.showTextDocument(doc); diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 8cd86c21e1d..7919997ce33 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -8,18 +8,19 @@ export function run(ctx: Ctx): Cmd { return async () => { const editor = ctx.activeRustEditor; - if (!editor) return; + const client = ctx.client; + if (!editor || !client) return; const textDocument: lc.TextDocumentIdentifier = { uri: editor.document.uri.toString(), }; const params: RunnablesParams = { textDocument, - position: ctx.client.code2ProtocolConverter.asPosition( + position: client.code2ProtocolConverter.asPosition( editor.selection.active, ), }; - const runnables = await ctx.client.sendRequest<Runnable[]>( + const runnables = await client.sendRequest<Runnable[]>( 'rust-analyzer/runnables', params, ); diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts index 5b8f6e4d94b..2ee80f910cd 100644 --- a/editors/code/src/commands/syntax_tree.ts +++ b/editors/code/src/commands/syntax_tree.ts @@ -76,7 +76,8 @@ class TextDocumentContentProvider provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> { const editor = vscode.window.activeTextEditor; - if (editor == null) return ''; + const client = this.ctx.client + if (!editor || !client) return ''; let range: lc.Range | undefined; @@ -84,16 +85,14 @@ class TextDocumentContentProvider if (uri.query === 'range=true') { range = editor.selection.isEmpty ? undefined - : this.ctx.client.code2ProtocolConverter.asRange( - editor.selection, - ); + : client.code2ProtocolConverter.asRange(editor.selection); } const request: SyntaxTreeParams = { textDocument: { uri: editor.document.uri.toString() }, range, }; - return this.ctx.client.sendRequest<string>( + return client.sendRequest<string>( 'rust-analyzer/syntaxTree', request, ); |
