@@ -16,9 +16,11 @@ import {
16
16
LanguageClient , LanguageClientOptions , RequestType , TransportKind , TextDocumentIdentifier , NotificationType , ErrorHandler ,
17
17
ErrorAction , CloseAction , State as ClientState , RevealOutputChannelOn , VersionedTextDocumentIdentifier , ExecuteCommandRequest ,
18
18
ExecuteCommandParams , ServerOptions , DocumentFilter , DidCloseTextDocumentNotification , DidOpenTextDocumentNotification ,
19
- WorkspaceFolder , DidChangeConfigurationNotification , NotificationType0
19
+ WorkspaceFolder , DidChangeConfigurationNotification , NotificationType0 , Middleware , Proposed
20
20
} from 'vscode-languageclient/node' ;
21
21
22
+ import { DiagnosticProviderMiddleware , VDiagnosticResult } from 'vscode-languageclient/lib/common/proposed.diagnostic' ;
23
+
22
24
import { findEslint , convert2RegExp , toOSPath , toPosixPath , Semaphore } from './utils' ;
23
25
import { TaskProvider } from './tasks' ;
24
26
@@ -109,6 +111,40 @@ namespace PatternItem {
109
111
}
110
112
111
113
type RunValues = 'onType' | 'onSave' ;
114
+ namespace RunValues {
115
+ export function from ( value : unknown ) : RunValues {
116
+ if ( ! Is . string ( value ) ) {
117
+ return 'onType' ;
118
+ }
119
+ switch ( value . toLowerCase ( ) ) {
120
+ case 'ontype' :
121
+ return 'onType' ;
122
+ case 'onsave' :
123
+ return 'onSave' ;
124
+ default :
125
+ return 'onType' ;
126
+ }
127
+ }
128
+ }
129
+
130
+ type DiagnosticMode = 'push' | 'pull' ;
131
+ namespace DiagnosticMode {
132
+ export const push = 'push' ;
133
+ export const pull = 'pull' ;
134
+ export function from ( value : unknown ) : DiagnosticMode {
135
+ if ( ! Is . string ( value ) ) {
136
+ return 'push' ;
137
+ }
138
+ switch ( value . toLowerCase ( ) ) {
139
+ case 'push' :
140
+ return push ;
141
+ case 'pull' :
142
+ return pull ;
143
+ default :
144
+ return push ;
145
+ }
146
+ }
147
+ }
112
148
113
149
interface CodeActionSettings {
114
150
disableRuleComment : {
@@ -193,6 +229,7 @@ interface ConfigurationSettings {
193
229
run : RunValues ;
194
230
nodePath : string | null ;
195
231
workspaceFolder : WorkspaceFolder | undefined ;
232
+ diagnosticMode : DiagnosticMode ;
196
233
workingDirectory : ModeItem | DirectoryItem | undefined ;
197
234
}
198
235
@@ -1355,6 +1392,21 @@ function realActivate(context: ExtensionContext): void {
1355
1392
const newContext : CodeActionContext = Object . assign ( { } , context , { diagnostics : eslintDiagnostics } as CodeActionContext ) ;
1356
1393
return next ( document , range , newContext , token ) ;
1357
1394
} ,
1395
+ provideDiagnostics : ( document , context , token , next ) : ProviderResult < VDiagnosticResult > => {
1396
+ // If the document is not sync return early
1397
+ if ( ! syncedDocuments . has ( document . uri . toString ( ) ) ) {
1398
+ return { unmodified : true } ;
1399
+ }
1400
+ if ( context . triggerKind === Proposed . DiagnosticTriggerKind . Opened || context . triggerKind === Proposed . DiagnosticTriggerKind . Invoked ) {
1401
+ return next ( document , context , token ) ;
1402
+ }
1403
+ const config = Workspace . getConfiguration ( 'eslint' , document . uri ) ;
1404
+ const runMode = RunValues . from ( config . get < RunValues > ( 'run' , 'onType' ) ) ;
1405
+ if ( runMode === 'onType' && context . triggerKind === Proposed . DiagnosticTriggerKind . Saved || runMode === 'onSave' && context . triggerKind === Proposed . DiagnosticTriggerKind . Typed ) {
1406
+ return { unmodified : true } ;
1407
+ }
1408
+ return next ( document , context , token ) ;
1409
+ } ,
1358
1410
workspace : {
1359
1411
didChangeWatchedFile : ( event , next ) => {
1360
1412
probeFailed . clear ( ) ;
@@ -1441,10 +1493,11 @@ function realActivate(context: ExtensionContext): void {
1441
1493
quiet : config . get ( 'quiet' , false ) ,
1442
1494
onIgnoredFiles : ESLintSeverity . from ( config . get < string > ( 'onIgnoredFiles' , ESLintSeverity . off ) ) ,
1443
1495
options : config . get ( 'options' , { } ) ,
1444
- run : config . get ( 'run' , 'onType' ) ,
1496
+ run : RunValues . from ( config . get ( 'run' , 'onType' ) ) ,
1445
1497
nodePath : config . get ( 'nodePath' , null ) ,
1446
1498
workingDirectory : undefined ,
1447
1499
workspaceFolder : undefined ,
1500
+ diagnosticMode : DiagnosticMode . from ( config . get < DiagnosticMode > ( 'experimental.diagnosticMode' , 'push' ) ) ,
1448
1501
codeAction : {
1449
1502
disableRuleComment : config . get ( 'codeAction.disableRuleComment' , { enable : true , location : 'separateLine' as 'separateLine' } ) ,
1450
1503
showDocumentation : config . get ( 'codeAction.showDocumentation' , { enable : true } )
@@ -1547,7 +1600,7 @@ function realActivate(context: ExtensionContext): void {
1547
1600
return result ;
1548
1601
}
1549
1602
}
1550
- }
1603
+ } as Middleware & DiagnosticProviderMiddleware
1551
1604
} ;
1552
1605
1553
1606
let client : LanguageClient ;
0 commit comments