@@ -100,19 +100,28 @@ class ProjectLoggerImpl implements ProjectLogger {
100
100
}
101
101
}
102
102
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:" ;
103
113
const fileProtocol = "file://" ;
104
114
function 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 ) ;
109
116
}
117
+
110
118
function fileNameToUri ( fileName : string ) : string {
111
- return fileProtocol + fileName ;
119
+ return encodeURI ( fileProtocol + fileName ) ;
112
120
}
113
121
114
122
export interface NgServiceInfo {
115
123
fileName : string ;
124
+ languageId ?: string ;
116
125
service ?: LanguageService ;
117
126
offset ?: number ;
118
127
}
@@ -126,6 +135,7 @@ export class TextDocuments {
126
135
private projectService : ProjectService ;
127
136
private logger : ProjectLoggerImpl ;
128
137
private host : ProjectServiceHostImpl ;
138
+ private languageIds = new Map < string , string > ( ) ;
129
139
private changeNumber = 0 ;
130
140
131
141
constructor ( private event ?: ( event : TextDocumentEvent ) => void ) {
@@ -150,6 +160,7 @@ export class TextDocuments {
150
160
// TODO: Report errors
151
161
this . logger . msg ( `Config errors encountered and need to be reported: ${ configFileErrors . length } \n ${ configFileErrors . map ( error => error . messageText ) . join ( '\n ' ) } ` ) ;
152
162
}
163
+ this . languageIds . set ( event . textDocument . uri , event . textDocument . languageId ) ;
153
164
} ) ;
154
165
155
166
connection . onDidCloseTextDocument ( event => {
@@ -203,16 +214,17 @@ export class TextDocuments {
203
214
public getServiceInfo ( document : TextDocumentIdentifier , position ?: Position ) : NgServiceInfo {
204
215
const fileName = uriToFileName ( document . uri ) ;
205
216
const project = this . projectService . getProjectForFile ( fileName ) ;
217
+ const languageId = this . languageIds . get ( document . uri ) ;
206
218
if ( project ) {
207
219
const service = project . compilerService . ngService ;
208
220
if ( position ) {
209
221
// VSCode is 0 based, editor services are 1 based.
210
222
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 } ;
212
224
}
213
- return { fileName, service} ;
225
+ return { fileName, service, languageId } ;
214
226
}
215
- return { fileName} ;
227
+ return { fileName, languageId } ;
216
228
}
217
229
218
230
public ifUnchanged ( f : ( ) => void ) : ( ) => void {
0 commit comments