@@ -4,6 +4,7 @@ import * as os from 'os';
44import { dirname } from 'path' ;
55import * as net from 'net' ;
66import { URL } from 'url' ;
7+ import * as fs from 'fs' ;
78import { LanguageClient , LanguageClientOptions , StreamInfo , DocumentFilter , ErrorAction , CloseAction , RevealOutputChannelOn } from 'vscode-languageclient/node' ;
89import { Disposable , workspace , Uri , TextDocument , WorkspaceConfiguration , OutputChannel , window , WorkspaceFolder } from 'vscode' ;
910import { 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