@@ -33,6 +33,9 @@ const config: DenoPluginConfig = {
33
33
enable : true ,
34
34
} ;
35
35
36
+ let parsedImportMap : ImportMaps | null = null ;
37
+ let projectDirectory : string ;
38
+
36
39
module . exports = function init (
37
40
{ typescript } : { typescript : typeof ts_module } ,
38
41
) {
@@ -84,12 +87,10 @@ module.exports = function init(
84
87
return tsLs ;
85
88
}
86
89
87
- const projectDirectory = project . getCurrentDirectory ( ) ;
90
+ projectDirectory = project . getCurrentDirectory ( ) ;
88
91
// TypeScript plugins have a `cwd` of `/`, which causes issues with import resolution.
89
92
process . chdir ( projectDirectory ) ;
90
93
91
- let parsedImportMap : ImportMaps | null = null ;
92
-
93
94
const resolveTypeReferenceDirectives =
94
95
tsLsHost . resolveTypeReferenceDirectives ;
95
96
@@ -126,6 +127,7 @@ module.exports = function init(
126
127
containingFile : string ,
127
128
...rest
128
129
) => {
130
+ logger . info ( "resolveModuleNames" ) ;
129
131
if ( ! config . enable ) {
130
132
logger . info ( "plugin disabled." ) ;
131
133
return resolveModuleNames . call (
@@ -155,17 +157,21 @@ module.exports = function init(
155
157
) ;
156
158
157
159
if ( parsedModuleName == null ) {
160
+ logger . info ( `module "${ moduleName } " can not parsed` )
158
161
resolvedModules . push ( undefined ) ;
159
162
continue ;
160
163
}
161
164
162
165
const resolvedModule = resolveDenoModule ( parsedModuleName ) ;
163
166
164
167
if ( ! resolvedModule ) {
168
+ logger . info ( `module "${ moduleName } " can not resolved` )
165
169
resolvedModules . push ( undefined ) ;
166
170
continue ;
167
171
}
168
172
173
+ logger . info ( `module "${ moduleName } " -> ${ resolvedModule . filepath } ` ) ;
174
+
169
175
resolvedModules . push ( {
170
176
extension : resolvedModule . extension as ts_module . Extension ,
171
177
isExternalLibraryImport : false ,
@@ -297,6 +303,7 @@ module.exports = function init(
297
303
}
298
304
299
305
function getSemanticDiagnostics ( filename : string ) {
306
+ logger . info ( "getSemanticDiagnostics" ) ;
300
307
const diagnostics = tsLs . getSemanticDiagnostics ( filename ) ;
301
308
302
309
if ( ! config . enable ) {
@@ -359,7 +366,7 @@ module.exports = function init(
359
366
) ;
360
367
361
368
if ( parsedModuleName == null ) {
362
- d . code = 10001 ;
369
+ d . code = 10001 ; // InvalidRelativeImport
363
370
d . messageText =
364
371
`relative import path "${ moduleName } " not prefixed with / or ./ or ../` ;
365
372
return d ;
@@ -373,7 +380,7 @@ module.exports = function init(
373
380
374
381
if ( isHttpURL ( parsedModuleName ) ) {
375
382
d . code = 10002 ; // RemoteModuleNotExist
376
- d . messageText = `Could not find module ${ moduleName } locally` ;
383
+ d . messageText = `The remote module " ${ moduleName } " have not cached locally` ;
377
384
return d ;
378
385
}
379
386
@@ -384,11 +391,11 @@ module.exports = function init(
384
391
parsedModuleName . startsWith ( "file://" )
385
392
) {
386
393
d . code = 10003 ; // LocalModuleNotExist
387
- d . messageText = `Could not find module ${ moduleName } locally` ;
394
+ d . messageText = `Could not find module " ${ moduleName } " locally` ;
388
395
return d ;
389
396
}
390
397
391
- d . code = 10003 ; // InvalidImport
398
+ d . code = 10004 ; // InvalidImport
392
399
d . messageText =
393
400
`Import module "${ moduleName } " must be a relative path or remote HTTP URL` ;
394
401
}
@@ -411,9 +418,18 @@ module.exports = function init(
411
418
onConfigurationChanged ( c : DenoPluginConfig ) {
412
419
logger . info ( "config change to:\n" + JSON . stringify ( c , null , " " ) ) ;
413
420
Object . assign ( config , c ) ;
421
+
422
+ if ( config . importmap != null ) {
423
+ parsedImportMap = parseImportMapFromFile (
424
+ projectDirectory ,
425
+ config . importmap ,
426
+ ) ;
427
+ }
428
+
414
429
pluginInfo . project . markAsDirty ( ) ;
415
430
pluginInfo . project . refreshDiagnostics ( ) ;
416
431
pluginInfo . project . updateGraph ( ) ;
432
+ pluginInfo . languageService . getProgram ( ) ?. emit ( ) ;
417
433
} ,
418
434
} ;
419
435
} ;
0 commit comments