@@ -17,6 +17,7 @@ import { activateTaskProvider, runCommand } from './tasks';
17
17
18
18
import * as child_process from 'child_process' ;
19
19
import * as fs from 'fs' ;
20
+ import path = require( 'path' ) ;
20
21
21
22
import { commands , ExtensionContext , IndentAction , languages , TextEditor ,
22
23
TextEditorEdit , window , workspace , TextDocument , WorkspaceFolder , Disposable , Uri ,
@@ -53,6 +54,11 @@ function didOpenTextDocument(document: TextDocument, context: ExtensionContext):
53
54
return ;
54
55
}
55
56
folder = getOuterMostWorkspaceFolder ( folder ) ;
57
+ folder = getCargoTomlWorkspace ( folder , document . uri . fsPath ) ;
58
+ if ( ! folder ) {
59
+ stopSpinner ( `RLS: Cargo.toml missing` ) ;
60
+ return ;
61
+ }
56
62
57
63
if ( ! workspaces . has ( folder . uri . toString ( ) ) ) {
58
64
const workspace = new ClientWorkspace ( folder ) ;
@@ -82,6 +88,27 @@ function sortedWorkspaceFolders(): string[] {
82
88
return _sortedWorkspaceFolders || [ ] ;
83
89
}
84
90
91
+ function getCargoTomlWorkspace ( cur_workspace : WorkspaceFolder , file_path : string ) : WorkspaceFolder | undefined {
92
+ let current = file_path ;
93
+ const workspace_root = path . parse ( cur_workspace . uri . fsPath ) . dir ;
94
+ while ( true ) {
95
+ const old = current ;
96
+ current = path . dirname ( current ) ;
97
+ if ( old == current ) {
98
+ break ;
99
+ }
100
+ if ( workspace_root == path . parse ( current ) . dir ) {
101
+ break ;
102
+ }
103
+
104
+ const cargo_path = path . join ( current , 'Cargo.toml' ) ;
105
+ if ( fs . existsSync ( cargo_path ) ) {
106
+ return { ...cur_workspace , uri : Uri . parse ( current ) } ;
107
+ }
108
+ }
109
+ return undefined ;
110
+ }
111
+
85
112
function getOuterMostWorkspaceFolder ( folder : WorkspaceFolder ) : WorkspaceFolder {
86
113
const sorted = sortedWorkspaceFolders ( ) ;
87
114
for ( const element of sorted ) {
@@ -146,8 +173,6 @@ class ClientWorkspace {
146
173
}
147
174
148
175
async start ( context : ExtensionContext ) {
149
- // These methods cannot throw an error, so we can drop it.
150
- warnOnMissingCargoToml ( ) ;
151
176
152
177
startSpinner ( 'RLS' , 'Starting' ) ;
153
178
@@ -436,15 +461,6 @@ class ClientWorkspace {
436
461
}
437
462
}
438
463
439
- async function warnOnMissingCargoToml ( ) {
440
- const files = await workspace . findFiles ( 'Cargo.toml' ) ;
441
-
442
- if ( files . length < 1 ) {
443
- window . showWarningMessage (
444
- 'A Cargo.toml file must be at the root of the workspace in order to support all features'
445
- ) ;
446
- }
447
- }
448
464
449
465
450
466
function configureLanguage ( context : ExtensionContext ) {
0 commit comments