File tree Expand file tree Collapse file tree 3 files changed +29
-12
lines changed Expand file tree Collapse file tree 3 files changed +29
-12
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,6 @@ import {
15
15
isRustEditor ,
16
16
RustEditor ,
17
17
RustDocument ,
18
- closeDocument ,
19
18
} from "./util" ;
20
19
import { startDebugSession , makeDebugConfig } from "./debug" ;
21
20
import { LanguageClient } from "vscode-languageclient/node" ;
@@ -324,7 +323,6 @@ async function revealParentChain(document: RustDocument, ctx: CtxInit) {
324
323
if ( parentChain . length >= maxDepth ) {
325
324
// this is an odd case that can happen when we change a crate version but we'd still have
326
325
// a open file referencing the old version
327
- await closeDocument ( document ) ;
328
326
return ;
329
327
}
330
328
} while ( ! ctx . dependencies ?. contains ( documentPath ) ) ;
Original file line number Diff line number Diff line change @@ -285,14 +285,38 @@ export class Ctx {
285
285
} ) ;
286
286
287
287
this . pushExtCleanup ( this . _treeView ) ;
288
- vscode . window . onDidChangeActiveTextEditor ( ( e ) => {
288
+ vscode . window . onDidChangeActiveTextEditor ( async ( e ) => {
289
289
// we should skip documents that belong to the current workspace
290
- if ( e && isRustEditor ( e ) && ! isDocumentInWorkspace ( e . document ) ) {
291
- execRevealDependency ( e ) . catch ( ( reason ) => {
292
- void vscode . window . showErrorMessage ( `Dependency error: ${ reason } ` ) ;
293
- } ) ;
290
+ if ( this . shouldRevealDependency ( e ) ) {
291
+ try {
292
+ await execRevealDependency ( e ) ;
293
+ } catch ( reason ) {
294
+ await vscode . window . showErrorMessage ( `Dependency error: ${ reason } ` ) ;
295
+ }
294
296
}
295
297
} ) ;
298
+
299
+ this . treeView ?. onDidChangeVisibility ( async ( e ) => {
300
+ if ( e . visible ) {
301
+ const activeEditor = vscode . window . activeTextEditor ;
302
+ if ( this . shouldRevealDependency ( activeEditor ) ) {
303
+ try {
304
+ await execRevealDependency ( activeEditor ) ;
305
+ } catch ( reason ) {
306
+ await vscode . window . showErrorMessage ( `Dependency error: ${ reason } ` ) ;
307
+ }
308
+ }
309
+ }
310
+ } ) ;
311
+ }
312
+
313
+ private shouldRevealDependency ( e : vscode . TextEditor | undefined ) : e is RustEditor {
314
+ return (
315
+ e !== undefined &&
316
+ isRustEditor ( e ) &&
317
+ ! isDocumentInWorkspace ( e . document ) &&
318
+ ( this . treeView ?. visible || false )
319
+ ) ;
296
320
}
297
321
298
322
async restart ( ) {
Original file line number Diff line number Diff line change @@ -125,11 +125,6 @@ export function isDocumentInWorkspace(document: RustDocument): boolean {
125
125
return false ;
126
126
}
127
127
128
- export async function closeDocument ( document : RustDocument ) {
129
- await vscode . window . showTextDocument ( document , { preview : true , preserveFocus : false } ) ;
130
- await vscode . commands . executeCommand ( "workbench.action.closeActiveEditor" ) ;
131
- }
132
-
133
128
export function isValidExecutable ( path : string ) : boolean {
134
129
log . debug ( "Checking availability of a binary at" , path ) ;
135
130
You can’t perform that action at this time.
0 commit comments