@@ -100,19 +100,28 @@ class ProjectLoggerImpl implements ProjectLogger {
100100 }
101101}
102102
103+ function removePrefix ( value : string , ...prefixes : string [ ] ) : string {
104+ for ( const prefix of prefixes ) {
105+ if ( value && value . startsWith ( prefix ) ) {
106+ return value . substr ( prefix . length ) ;
107+ }
108+ }
109+ return value ;
110+ }
111+
112+ const privateProtocol = "private:" ;
103113const fileProtocol = "file://" ;
104114function uriToFileName ( uri : string ) : string {
105- if ( uri && uri . startsWith ( fileProtocol ) ) {
106- return uri . substr ( fileProtocol . length ) ;
107- }
108- return uri ;
115+ return removePrefix ( decodeURI ( uri ) , fileProtocol , privateProtocol ) ;
109116}
117+
110118function fileNameToUri ( fileName : string ) : string {
111- return fileProtocol + fileName ;
119+ return encodeURI ( fileProtocol + fileName ) ;
112120}
113121
114122export interface NgServiceInfo {
115123 fileName : string ;
124+ languageId ?: string ;
116125 service ?: LanguageService ;
117126 offset ?: number ;
118127}
@@ -126,6 +135,7 @@ export class TextDocuments {
126135 private projectService : ProjectService ;
127136 private logger : ProjectLoggerImpl ;
128137 private host : ProjectServiceHostImpl ;
138+ private languageIds = new Map < string , string > ( ) ;
129139 private changeNumber = 0 ;
130140
131141 constructor ( private event ?: ( event : TextDocumentEvent ) => void ) {
@@ -150,6 +160,7 @@ export class TextDocuments {
150160 // TODO: Report errors
151161 this . logger . msg ( `Config errors encountered and need to be reported: ${ configFileErrors . length } \n ${ configFileErrors . map ( error => error . messageText ) . join ( '\n ' ) } ` ) ;
152162 }
163+ this . languageIds . set ( event . textDocument . uri , event . textDocument . languageId ) ;
153164 } ) ;
154165
155166 connection . onDidCloseTextDocument ( event => {
@@ -203,16 +214,17 @@ export class TextDocuments {
203214 public getServiceInfo ( document : TextDocumentIdentifier , position ?: Position ) : NgServiceInfo {
204215 const fileName = uriToFileName ( document . uri ) ;
205216 const project = this . projectService . getProjectForFile ( fileName ) ;
217+ const languageId = this . languageIds . get ( document . uri ) ;
206218 if ( project ) {
207219 const service = project . compilerService . ngService ;
208220 if ( position ) {
209221 // VSCode is 0 based, editor services are 1 based.
210222 const offset = this . projectService . lineOffsetsToPositions ( fileName , [ { line : position . line + 1 , col : position . character + 1 } ] ) [ 0 ] ;
211- return { fileName, service, offset} ;
223+ return { fileName, service, offset, languageId } ;
212224 }
213- return { fileName, service} ;
225+ return { fileName, service, languageId } ;
214226 }
215- return { fileName} ;
227+ return { fileName, languageId } ;
216228 }
217229
218230 public ifUnchanged ( f : ( ) => void ) : ( ) => void {
0 commit comments