@@ -195,6 +195,7 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
195
195
196
196
const completionItems = new WeakMap < monaco . languages . CompletionItem , vscode . CompletionItem > ( ) ;
197
197
const codeLens = new WeakMap < monaco . languages . CodeLens , vscode . CodeLens > ( ) ;
198
+ const codeActions = new WeakMap < monaco . languages . CodeAction , vscode . CodeAction > ( ) ;
198
199
const documents = new WeakMap < monaco . editor . ITextModel , vscode . TextDocument > ( ) ;
199
200
200
201
disposables . value . push (
@@ -352,6 +353,46 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
352
353
return moncaoResult ;
353
354
} ,
354
355
} ) ,
356
+ monaco . languages . registerCodeActionProvider ( lang , {
357
+ provideCodeActions : async ( model , range , context ) => {
358
+ const diagnostics : vscode . Diagnostic [ ] = [ ] ;
359
+ for ( const marker of context . markers ) {
360
+ const diagnostic = _diagnostics . get ( marker ) ;
361
+ if ( diagnostic ) {
362
+ diagnostics . push ( diagnostic ) ;
363
+ }
364
+ }
365
+ const codeResult = await ls . doCodeActions (
366
+ model . uri . toString ( ) ,
367
+ monaco2code . asRange ( range ) ,
368
+ {
369
+ diagnostics : diagnostics ,
370
+ only : context . only ? [ context . only ] : undefined ,
371
+ } ,
372
+ ) ;
373
+ if ( codeResult ) {
374
+ const monacoResult = codeResult . map ( code2monaco . asCodeAction ) ;
375
+ for ( let i = 0 ; i < monacoResult . length ; i ++ ) {
376
+ codeActions . set ( monacoResult [ i ] , codeResult [ i ] ) ;
377
+ }
378
+ return {
379
+ actions : monacoResult ,
380
+ dispose : ( ) => { } ,
381
+ } ;
382
+ }
383
+ } ,
384
+ resolveCodeAction : async ( moncaoResult ) => {
385
+ let codeResult = codeActions . get ( moncaoResult ) ;
386
+ if ( codeResult ) {
387
+ codeResult = await ls . doCodeActionResolve ( codeResult ) ;
388
+ if ( codeResult ) {
389
+ moncaoResult = code2monaco . asCodeAction ( codeResult ) ;
390
+ codeActions . set ( moncaoResult , codeResult ) ;
391
+ }
392
+ }
393
+ return moncaoResult ;
394
+ } ,
395
+ } ) ,
355
396
monaco . languages . registerCompletionItemProvider ( lang , {
356
397
// https://github.com/johnsoncodehk/volar/blob/2f786182250d27e99cc3714fbfc7d209616e2289/packages/vue-language-server/src/registers/registerlanguageFeatures.ts#L57
357
398
triggerCharacters : '!@#$%^&*()_+-=`~{}|[]\:";\'<>?,./ ' . split ( '' ) ,
@@ -396,6 +437,8 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
396
437
}
397
438
}
398
439
440
+ const _diagnostics = new WeakMap < monaco . editor . IMarkerData , vscode . Diagnostic > ( ) ;
441
+
399
442
export function setupValidate ( editor : monaco . editor . IStandaloneCodeEditor , ls : LanguageService ) {
400
443
const worker = async ( ) => {
401
444
const model = editor . getModel ( ) ;
@@ -407,13 +450,13 @@ export function setupValidate(editor: monaco.editor.IStandaloneCodeEditor, ls: L
407
450
monaco . editor . setModelMarkers (
408
451
model ,
409
452
lang ,
410
- unfinishResult . map ( code2monaco . asMarkerData ) ,
453
+ toMarkers ( unfinishResult ) ,
411
454
) ;
412
455
} ) ;
413
456
monaco . editor . setModelMarkers (
414
457
model ,
415
458
lang ,
416
- diagnostics . map ( code2monaco . asMarkerData ) ,
459
+ toMarkers ( diagnostics ) ,
417
460
) ;
418
461
} ;
419
462
@@ -428,3 +471,11 @@ export function setupValidate(editor: monaco.editor.IStandaloneCodeEditor, ls: L
428
471
} ) ,
429
472
) ;
430
473
}
474
+
475
+ function toMarkers ( errors : vscode . Diagnostic [ ] ) {
476
+ return errors . map ( error => {
477
+ const marker = code2monaco . asMarkerData ( error ) ;
478
+ _diagnostics . set ( marker , error ) ;
479
+ return marker ;
480
+ } ) ;
481
+ }
0 commit comments