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

Commit

Permalink
fix intellisense on cached files
Browse files Browse the repository at this point in the history
  • Loading branch information
justjavac committed May 16, 2020
1 parent 4acd3a1 commit 2661ebe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import {
normalizeFilepath,
pathExistsSync,
isHttpURL,
isInDenoDir,
} from "./utils";

import { universalModuleResolver } from "./module_resolver/universal_module_resolver";
import { HashMeta } from "./module_resolver/hash_meta";

let logger: Logger;
let pluginInfo: ts_module.server.PluginCreateInfo;
Expand Down Expand Up @@ -471,10 +473,24 @@ function parseModuleName(
): string | undefined {
if (parsedImportMap != null) {
try {
let scriptURL: URL;
if (isInDenoDir(containingFile)) {
const meta = HashMeta.create(`${containingFile}.metadata.json`);
if (meta && meta.url) {
scriptURL = meta.url;
} else {
scriptURL = new URL("file:///" + path.dirname(containingFile) + "/")
}
} else {
scriptURL = new URL("file:///" + path.dirname(containingFile) + "/")
}

logger && logger.info(`baseUrl: ${scriptURL}`)

const moduleUrl = resolve(
moduleName,
parsedImportMap,
new URL("file:///" + path.dirname(containingFile) + "/"),
scriptURL,
);

if (moduleUrl.protocol === "file:") {
Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export function getDenoDepsDir(): string {
return path.join(getDenoDir(), "deps");
}

export function isInDenoDir(filepath: string): boolean {
filepath = normalizeFilepath(filepath);
const denoDir = getDenoDir();
return filepath.startsWith(denoDir);
}

export function getPluginPath(
tsLsHost: ts.LanguageServiceHost,
): string {
Expand Down

1 comment on commit 2661ebe

@justjavac
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.