11
22import * as vscode from 'vscode' ;
3- import { IAnnotator , AnnotatorType } from './notifications' ;
3+ import { AnnotatorType } from './notifications' ;
44import { LanguageClient } from 'vscode-languageclient' ;
55import * as notifications from "./notifications" ;
66
@@ -46,28 +46,42 @@ function requestAnnotatorsImpl(editor: vscode.TextEditor, client: LanguageClient
4646
4747 let params :notifications . AnnotatorParams = { uri : editor . document . uri . toString ( ) } ;
4848 client . sendRequest < notifications . IAnnotator [ ] > ( "emmy/annotator" , params ) . then ( list => {
49+ let map : Map < AnnotatorType , vscode . Range [ ] > = new Map ( ) ;
50+ map . set ( AnnotatorType . DocType , [ ] ) ;
51+ map . set ( AnnotatorType . Param , [ ] ) ;
52+ map . set ( AnnotatorType . Global , [ ] ) ;
53+
4954 list . forEach ( data => {
5055 let uri = vscode . Uri . parse ( data . uri ) ;
5156 vscode . window . visibleTextEditors . forEach ( ( editor ) => {
5257 let docUri = editor . document . uri ;
5358 if ( uri . path . toLowerCase ( ) === docUri . path . toLowerCase ( ) ) {
54- updateAnnotators ( editor , data ) ;
59+ var list = map . get ( data . type ) ;
60+ if ( list === undefined ) {
61+ list = data . ranges ;
62+ } else {
63+ list = list . concat ( data . ranges ) ;
64+ }
65+ map . set ( data . type , list ) ;
5566 }
5667 } ) ;
5768 } ) ;
69+ map . forEach ( ( v , k ) => {
70+ updateAnnotators ( editor , k , v ) ;
71+ } ) ;
5872 } ) ;
5973}
6074
61- function updateAnnotators ( editor : vscode . TextEditor , annotator : IAnnotator ) {
62- switch ( annotator . type ) {
75+ function updateAnnotators ( editor : vscode . TextEditor , type : AnnotatorType , ranges : vscode . Range [ ] ) {
76+ switch ( type ) {
6377 case AnnotatorType . Param :
64- editor . setDecorations ( D_PARAM , annotator . ranges ) ;
78+ editor . setDecorations ( D_PARAM , ranges ) ;
6579 break ;
6680 case AnnotatorType . Global :
67- editor . setDecorations ( D_GLOBAL , annotator . ranges ) ;
81+ editor . setDecorations ( D_GLOBAL , ranges ) ;
6882 break ;
6983 case AnnotatorType . DocType :
70- editor . setDecorations ( D_DOC_TYPE , annotator . ranges ) ;
84+ editor . setDecorations ( D_DOC_TYPE , ranges ) ;
7185 break ;
7286 }
7387}
0 commit comments