Skip to content

Commit 77b0c2c

Browse files
toscmrandy3k
authored andcommitted
fix(lsp): ignore virtual and deleted files for diagnostics
1 parent 797a352 commit 77b0c2c

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

src/languageService.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as os from 'os';
44
import { dirname } from 'path';
55
import * as net from 'net';
66
import { URL } from 'url';
7+
import * as fs from 'fs';
78
import { LanguageClient, LanguageClientOptions, StreamInfo, DocumentFilter, ErrorAction, CloseAction, RevealOutputChannelOn } from 'vscode-languageclient/node';
89
import { Disposable, workspace, Uri, TextDocument, WorkspaceConfiguration, OutputChannel, window, WorkspaceFolder } from 'vscode';
910
import { DisposableProcess, getRLibPaths, getRpath, promptToInstallRPackage, spawn, substituteVariables } from './util';
@@ -137,6 +138,23 @@ export class LanguageService implements Disposable {
137138
configurationSection: 'r.lsp',
138139
fileEvents: workspace.createFileSystemWatcher('**/*.{R,r}'),
139140
},
141+
middleware: {
142+
handleDiagnostics: (uri, diagnostics, next) => {
143+
const supportedSchemes = ['file', 'untitled', 'vscode-notebook-cell'];
144+
145+
// Drop diagnostics for unsupported schemes (like git://)
146+
if (!supportedSchemes.includes(uri.scheme)) {
147+
return next(uri, []);
148+
}
149+
150+
// Drop diagnostics for files that no longer exist on disk
151+
if (uri.scheme === 'file' && !fs.existsSync(uri.fsPath)) {
152+
return next(uri, []);
153+
}
154+
155+
return next(uri, diagnostics);
156+
}
157+
},
140158
revealOutputChannelOn: RevealOutputChannelOn.Never,
141159
errorHandler: {
142160
error: () => {
@@ -324,8 +342,11 @@ export class LanguageService implements Disposable {
324342
this.startMultiLanguageService();
325343
} else {
326344
const documentSelector: DocumentFilter[] = [
327-
{ language: 'r' },
328-
{ language: 'rmd' },
345+
{ scheme: 'file', language: 'r' },
346+
{ scheme: 'file', language: 'rmd' },
347+
{ scheme: 'untitled', language: 'r' },
348+
{ scheme: 'untitled', language: 'rmd' },
349+
{ scheme: 'vscode-notebook-cell', language: 'r' },
329350
];
330351

331352
const workspaceFolder = workspace.workspaceFolders?.[0];

0 commit comments

Comments
 (0)