File tree Expand file tree Collapse file tree 5 files changed +24
-21
lines changed
editors/code/src/commands Expand file tree Collapse file tree 5 files changed +24
-21
lines changed Original file line number Diff line number Diff line change @@ -6,21 +6,21 @@ import { Ctx, Cmd } from '../ctx';
6
6
export function matchingBrace ( ctx : Ctx ) : Cmd {
7
7
return async ( ) => {
8
8
const editor = ctx . activeRustEditor ;
9
- if ( ! editor ) {
10
- return ;
11
- }
9
+ const client = ctx . client ;
10
+ if ( ! editor || ! client ) return ;
11
+
12
12
const request : FindMatchingBraceParams = {
13
13
textDocument : { uri : editor . document . uri . toString ( ) } ,
14
14
offsets : editor . selections . map ( s =>
15
- ctx . client . code2ProtocolConverter . asPosition ( s . active ) ,
15
+ client . code2ProtocolConverter . asPosition ( s . active ) ,
16
16
) ,
17
17
} ;
18
- const response = await ctx . client . sendRequest < lc . Position [ ] > (
18
+ const response = await client . sendRequest < lc . Position [ ] > (
19
19
'rust-analyzer/findMatchingBrace' ,
20
20
request ,
21
21
) ;
22
22
editor . selections = editor . selections . map ( ( sel , idx ) => {
23
- const active = ctx . client . protocol2CodeConverter . asPosition (
23
+ const active = client . protocol2CodeConverter . asPosition (
24
24
response [ idx ] ,
25
25
) ;
26
26
const anchor = sel . isEmpty ? active : sel . anchor ;
Original file line number Diff line number Diff line change @@ -6,15 +6,17 @@ import { Cmd, Ctx } from '../ctx';
6
6
export function onEnter ( ctx : Ctx ) : Cmd {
7
7
return async ( event : { text : string } ) => {
8
8
const editor = ctx . activeRustEditor ;
9
+ const client = ctx . client ;
9
10
if ( ! editor || event . text !== '\n' ) return false ;
11
+ if ( ! client ) return false ;
10
12
11
13
const request : lc . TextDocumentPositionParams = {
12
14
textDocument : { uri : editor . document . uri . toString ( ) } ,
13
- position : ctx . client . code2ProtocolConverter . asPosition (
15
+ position : client . code2ProtocolConverter . asPosition (
14
16
editor . selection . active ,
15
17
) ,
16
18
} ;
17
- const change = await ctx . client . sendRequest < undefined | SourceChange > (
19
+ const change = await client . sendRequest < undefined | SourceChange > (
18
20
'rust-analyzer/onEnter' ,
19
21
request ,
20
22
) ;
Original file line number Diff line number Diff line change @@ -6,23 +6,24 @@ import { Ctx, Cmd } from '../ctx';
6
6
export function parentModule ( ctx : Ctx ) : Cmd {
7
7
return async ( ) => {
8
8
const editor = ctx . activeRustEditor ;
9
- if ( ! editor ) return ;
9
+ const client = ctx . client ;
10
+ if ( ! editor || ! client ) return ;
10
11
11
12
const request : lc . TextDocumentPositionParams = {
12
13
textDocument : { uri : editor . document . uri . toString ( ) } ,
13
- position : ctx . client . code2ProtocolConverter . asPosition (
14
+ position : client . code2ProtocolConverter . asPosition (
14
15
editor . selection . active ,
15
16
) ,
16
17
} ;
17
- const response = await ctx . client . sendRequest < lc . Location [ ] > (
18
+ const response = await client . sendRequest < lc . Location [ ] > (
18
19
'rust-analyzer/parentModule' ,
19
20
request ,
20
21
) ;
21
22
const loc = response [ 0 ] ;
22
23
if ( loc == null ) return ;
23
24
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 ) ;
26
27
27
28
const doc = await vscode . workspace . openTextDocument ( uri ) ;
28
29
const e = await vscode . window . showTextDocument ( doc ) ;
Original file line number Diff line number Diff line change @@ -8,18 +8,19 @@ export function run(ctx: Ctx): Cmd {
8
8
9
9
return async ( ) => {
10
10
const editor = ctx . activeRustEditor ;
11
- if ( ! editor ) return ;
11
+ const client = ctx . client ;
12
+ if ( ! editor || ! client ) return ;
12
13
13
14
const textDocument : lc . TextDocumentIdentifier = {
14
15
uri : editor . document . uri . toString ( ) ,
15
16
} ;
16
17
const params : RunnablesParams = {
17
18
textDocument,
18
- position : ctx . client . code2ProtocolConverter . asPosition (
19
+ position : client . code2ProtocolConverter . asPosition (
19
20
editor . selection . active ,
20
21
) ,
21
22
} ;
22
- const runnables = await ctx . client . sendRequest < Runnable [ ] > (
23
+ const runnables = await client . sendRequest < Runnable [ ] > (
23
24
'rust-analyzer/runnables' ,
24
25
params ,
25
26
) ;
Original file line number Diff line number Diff line change @@ -76,24 +76,23 @@ class TextDocumentContentProvider
76
76
77
77
provideTextDocumentContent ( uri : vscode . Uri ) : vscode . ProviderResult < string > {
78
78
const editor = vscode . window . activeTextEditor ;
79
- if ( editor == null ) return '' ;
79
+ const client = this . ctx . client
80
+ if ( ! editor || ! client ) return '' ;
80
81
81
82
let range : lc . Range | undefined ;
82
83
83
84
// When the range based query is enabled we take the range of the selection
84
85
if ( uri . query === 'range=true' ) {
85
86
range = editor . selection . isEmpty
86
87
? undefined
87
- : this . ctx . client . code2ProtocolConverter . asRange (
88
- editor . selection ,
89
- ) ;
88
+ : client . code2ProtocolConverter . asRange ( editor . selection ) ;
90
89
}
91
90
92
91
const request : SyntaxTreeParams = {
93
92
textDocument : { uri : editor . document . uri . toString ( ) } ,
94
93
range,
95
94
} ;
96
- return this . ctx . client . sendRequest < string > (
95
+ return client . sendRequest < string > (
97
96
'rust-analyzer/syntaxTree' ,
98
97
request ,
99
98
) ;
You can’t perform that action at this time.
0 commit comments