Skip to content
This repository was archived by the owner on Sep 4, 2020. It is now read-only.

Commit 2661ebe

Browse files
committed
fix intellisense on cached files
1 parent 4acd3a1 commit 2661ebe

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import {
1616
normalizeFilepath,
1717
pathExistsSync,
1818
isHttpURL,
19+
isInDenoDir,
1920
} from "./utils";
2021

2122
import { universalModuleResolver } from "./module_resolver/universal_module_resolver";
23+
import { HashMeta } from "./module_resolver/hash_meta";
2224

2325
let logger: Logger;
2426
let pluginInfo: ts_module.server.PluginCreateInfo;
@@ -471,10 +473,24 @@ function parseModuleName(
471473
): string | undefined {
472474
if (parsedImportMap != null) {
473475
try {
476+
let scriptURL: URL;
477+
if (isInDenoDir(containingFile)) {
478+
const meta = HashMeta.create(`${containingFile}.metadata.json`);
479+
if (meta && meta.url) {
480+
scriptURL = meta.url;
481+
} else {
482+
scriptURL = new URL("file:///" + path.dirname(containingFile) + "/")
483+
}
484+
} else {
485+
scriptURL = new URL("file:///" + path.dirname(containingFile) + "/")
486+
}
487+
488+
logger && logger.info(`baseUrl: ${scriptURL}`)
489+
474490
const moduleUrl = resolve(
475491
moduleName,
476492
parsedImportMap,
477-
new URL("file:///" + path.dirname(containingFile) + "/"),
493+
scriptURL,
478494
);
479495

480496
if (moduleUrl.protocol === "file:") {

src/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export function getDenoDepsDir(): string {
3737
return path.join(getDenoDir(), "deps");
3838
}
3939

40+
export function isInDenoDir(filepath: string): boolean {
41+
filepath = normalizeFilepath(filepath);
42+
const denoDir = getDenoDir();
43+
return filepath.startsWith(denoDir);
44+
}
45+
4046
export function getPluginPath(
4147
tsLsHost: ts.LanguageServiceHost,
4248
): string {

0 commit comments

Comments
 (0)