@@ -33,7 +33,7 @@ export function outputChannel() {
33
33
}
34
34
35
35
export interface RustAnalyzerExtensionApi {
36
- client : lc . LanguageClient ;
36
+ client ? : lc . LanguageClient ;
37
37
}
38
38
39
39
export async function activate (
@@ -48,6 +48,23 @@ export async function activate(
48
48
}
49
49
50
50
async function tryActivate ( context : vscode . ExtensionContext ) : Promise < RustAnalyzerExtensionApi > {
51
+ // We only support local folders, not eg. Live Share (`vlsl:` scheme), so don't activate if
52
+ // only those are in use.
53
+ // (r-a still somewhat works with Live Share, because commands are tunneled to the host)
54
+ const folders = ( vscode . workspace . workspaceFolders || [ ] ) . filter ( ( folder ) =>
55
+ folder . uri . scheme == "file"
56
+ ) ;
57
+ const rustDocuments = vscode . workspace . textDocuments . filter ( ( document ) =>
58
+ isRustDocument ( document )
59
+ ) ;
60
+
61
+ if ( folders . length == 0 && rustDocuments . length == 0 ) {
62
+ // FIXME: Ideally we would choose not to activate at all (and avoid registering
63
+ // non-functional editor commands), but VS Code doesn't seem to have a good way of doing
64
+ // that
65
+ return { } ;
66
+ }
67
+
51
68
const config = new Config ( context ) ;
52
69
const state = new PersistentState ( context . globalState ) ;
53
70
const serverPath = await bootstrap ( context , config , state ) . catch ( ( err ) => {
@@ -60,18 +77,11 @@ async function tryActivate(context: vscode.ExtensionContext): Promise<RustAnalyz
60
77
throw new Error ( message ) ;
61
78
} ) ;
62
79
63
- if ( ( vscode . workspace . workspaceFolders || [ ] ) . length === 0 ) {
64
- const rustDocuments = vscode . workspace . textDocuments . filter ( ( document ) =>
65
- isRustDocument ( document )
66
- ) ;
67
- if ( rustDocuments . length > 0 ) {
68
- ctx = await Ctx . create ( config , context , serverPath , {
69
- kind : "Detached Files" ,
70
- files : rustDocuments ,
71
- } ) ;
72
- } else {
73
- throw new Error ( "no rust files are opened" ) ;
74
- }
80
+ if ( folders . length === 0 ) {
81
+ ctx = await Ctx . create ( config , context , serverPath , {
82
+ kind : "Detached Files" ,
83
+ files : rustDocuments ,
84
+ } ) ;
75
85
} else {
76
86
// Note: we try to start the server before we activate type hints so that it
77
87
// registers its `onDidChangeDocument` handler before us.
0 commit comments