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

Commit

Permalink
feat: improve auto-import completion detail
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Mar 3, 2020
1 parent c790727 commit 78fa0e8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
8 changes: 7 additions & 1 deletion core/deno_cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from "path";
import { URL } from "url";
import assert from "assert";

import { getDenoDepsDir } from "./deno";
import { HashMeta } from "./hash_meta";
Expand Down Expand Up @@ -37,7 +38,12 @@ export class CacheModule implements DenoCacheModule {
public filepath: string,
public url: URL,
private logger?: Logger
) {}
) {
assert(
path.isAbsolute(filepath),
`Deno Module filepath require absolute but got ${filepath}`
);
}
/**
* Resolve module in this cache file
* @param moduleName The module name is for unix style
Expand Down
26 changes: 24 additions & 2 deletions typescript-deno-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Logger } from "./logger";
import { ConfigurationManager, DenoPluginConfig } from "./configuration";
import { getDenoDts } from "../../core/deno";
import { ModuleResolver, ResolvedModule } from "../../core/module_resolver";
import { CacheModule } from "../../core/deno_cache";
import { pathExistsSync } from "../../core/util";
import { normalizeImportStatement } from "../../core/deno_normalize_import_statement";
import { readConfigurationFromVscodeSettings } from "../../core/vscode_settings";
Expand Down Expand Up @@ -146,7 +147,6 @@ export class DenoPlugin implements ts_module.server.PluginModule {
containingFile: string,
...rest
) => {
// containingFile may not be a file path, it may be `untitled:^Untitled-1`
if (!this.configurationManager.config.enable) {
return resolveTypeReferenceDirectives(
typeDirectiveNames,
Expand Down Expand Up @@ -240,7 +240,7 @@ export class DenoPlugin implements ts_module.server.PluginModule {
return details;
}

if (details) {
if (details && details.kindModifiers === "export") {
if (details.codeActions && details.codeActions.length) {
for (const ca of details.codeActions) {
for (const change of ca.changes) {
Expand All @@ -252,6 +252,28 @@ export class DenoPlugin implements ts_module.server.PluginModule {
}
}
}

if (details.source && details.source.length) {
for (const source of details.source) {
if (source.kind === "text") {
// text is always unix style
const text = source.text;

const absoluteFilepath = path.posix.resolve(text);

if (path.isAbsolute(absoluteFilepath)) {
const denoCache = CacheModule.create(
absoluteFilepath,
this.logger
);

if (denoCache) {
source.text = denoCache.url.href;
}
}
}
}
}
}

return details;
Expand Down

0 comments on commit 78fa0e8

Please sign in to comment.