Skip to content

Commit c8b98c4

Browse files
bors[bot]matklad
andauthored
Merge #2710
2710: Fix NPEs r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 6d23140 + cb41ffb commit c8b98c4

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

editors/code/src/commands/matching_brace.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ import { Ctx, Cmd } from '../ctx';
66
export function matchingBrace(ctx: Ctx): Cmd {
77
return async () => {
88
const editor = ctx.activeRustEditor;
9-
if (!editor) {
10-
return;
11-
}
9+
const client = ctx.client;
10+
if (!editor || !client) return;
11+
1212
const request: FindMatchingBraceParams = {
1313
textDocument: { uri: editor.document.uri.toString() },
1414
offsets: editor.selections.map(s =>
15-
ctx.client.code2ProtocolConverter.asPosition(s.active),
15+
client.code2ProtocolConverter.asPosition(s.active),
1616
),
1717
};
18-
const response = await ctx.client.sendRequest<lc.Position[]>(
18+
const response = await client.sendRequest<lc.Position[]>(
1919
'rust-analyzer/findMatchingBrace',
2020
request,
2121
);
2222
editor.selections = editor.selections.map((sel, idx) => {
23-
const active = ctx.client.protocol2CodeConverter.asPosition(
23+
const active = client.protocol2CodeConverter.asPosition(
2424
response[idx],
2525
);
2626
const anchor = sel.isEmpty ? active : sel.anchor;

editors/code/src/commands/on_enter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ import { Cmd, Ctx } from '../ctx';
66
export function onEnter(ctx: Ctx): Cmd {
77
return async (event: { text: string }) => {
88
const editor = ctx.activeRustEditor;
9+
const client = ctx.client;
910
if (!editor || event.text !== '\n') return false;
11+
if (!client) return false;
1012

1113
const request: lc.TextDocumentPositionParams = {
1214
textDocument: { uri: editor.document.uri.toString() },
13-
position: ctx.client.code2ProtocolConverter.asPosition(
15+
position: client.code2ProtocolConverter.asPosition(
1416
editor.selection.active,
1517
),
1618
};
17-
const change = await ctx.client.sendRequest<undefined | SourceChange>(
19+
const change = await client.sendRequest<undefined | SourceChange>(
1820
'rust-analyzer/onEnter',
1921
request,
2022
);

editors/code/src/commands/parent_module.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ import { Ctx, Cmd } from '../ctx';
66
export function parentModule(ctx: Ctx): Cmd {
77
return async () => {
88
const editor = ctx.activeRustEditor;
9-
if (!editor) return;
9+
const client = ctx.client;
10+
if (!editor || !client) return;
1011

1112
const request: lc.TextDocumentPositionParams = {
1213
textDocument: { uri: editor.document.uri.toString() },
13-
position: ctx.client.code2ProtocolConverter.asPosition(
14+
position: client.code2ProtocolConverter.asPosition(
1415
editor.selection.active,
1516
),
1617
};
17-
const response = await ctx.client.sendRequest<lc.Location[]>(
18+
const response = await client.sendRequest<lc.Location[]>(
1819
'rust-analyzer/parentModule',
1920
request,
2021
);
2122
const loc = response[0];
2223
if (loc == null) return;
2324

24-
const uri = ctx.client.protocol2CodeConverter.asUri(loc.uri);
25-
const range = ctx.client.protocol2CodeConverter.asRange(loc.range);
25+
const uri = client.protocol2CodeConverter.asUri(loc.uri);
26+
const range = client.protocol2CodeConverter.asRange(loc.range);
2627

2728
const doc = await vscode.workspace.openTextDocument(uri);
2829
const e = await vscode.window.showTextDocument(doc);

editors/code/src/commands/runnables.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ export function run(ctx: Ctx): Cmd {
88

99
return async () => {
1010
const editor = ctx.activeRustEditor;
11-
if (!editor) return;
11+
const client = ctx.client;
12+
if (!editor || !client) return;
1213

1314
const textDocument: lc.TextDocumentIdentifier = {
1415
uri: editor.document.uri.toString(),
1516
};
1617
const params: RunnablesParams = {
1718
textDocument,
18-
position: ctx.client.code2ProtocolConverter.asPosition(
19+
position: client.code2ProtocolConverter.asPosition(
1920
editor.selection.active,
2021
),
2122
};
22-
const runnables = await ctx.client.sendRequest<Runnable[]>(
23+
const runnables = await client.sendRequest<Runnable[]>(
2324
'rust-analyzer/runnables',
2425
params,
2526
);

editors/code/src/commands/syntax_tree.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,23 @@ class TextDocumentContentProvider
7676

7777
provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> {
7878
const editor = vscode.window.activeTextEditor;
79-
if (editor == null) return '';
79+
const client = this.ctx.client
80+
if (!editor || !client) return '';
8081

8182
let range: lc.Range | undefined;
8283

8384
// When the range based query is enabled we take the range of the selection
8485
if (uri.query === 'range=true') {
8586
range = editor.selection.isEmpty
8687
? undefined
87-
: this.ctx.client.code2ProtocolConverter.asRange(
88-
editor.selection,
89-
);
88+
: client.code2ProtocolConverter.asRange(editor.selection);
9089
}
9190

9291
const request: SyntaxTreeParams = {
9392
textDocument: { uri: editor.document.uri.toString() },
9493
range,
9594
};
96-
return this.ctx.client.sendRequest<string>(
95+
return client.sendRequest<string>(
9796
'rust-analyzer/syntaxTree',
9897
request,
9998
);

0 commit comments

Comments
 (0)