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

Commit

Permalink
fix: module import intelligent no work correctly when import from 'ht…
Browse files Browse the repository at this point in the history
…tp/server.ts'
  • Loading branch information
axetroy committed Feb 10, 2020
1 parent 4098c00 commit 055d062
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions server/src/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ class Deno {
return denoModuleFilepath
.replace(deno.DENO_DEPS_DIR, "")
.replace(/^(\/|\\\\)/, "")
.replace(/http(\/|\\\\)/, "http://")
.replace(/https(\/|\\\\)/, "https://");
.replace(/^http(\/|\\\\)/, "http://")
.replace(/^https(\/|\\\\)/, "https://");
}
// get deno dependencies files
public async getDependencies(
Expand All @@ -163,14 +163,20 @@ class Deno {
const promises = files.map(filename => {
const filepath = path.join(rootDir, filename);
return fs.stat(filepath).then(stat => {
if (stat.isDirectory()) {
const isInternalModule =
filename.startsWith("_") || filename.startsWith(".");
if (stat.isDirectory() && !isInternalModule) {
return this.getDependencies(filepath, deps);
} else if (stat.isFile() && filepath.endsWith(".headers.json")) {
} else if (
stat.isFile() &&
filepath.endsWith(".headers.json") &&
!isInternalModule
) {
const moduleFilepath = filepath.replace(/\.headers\.json$/, "");

deps.push({
url: this.filepath2url(moduleFilepath),
filepath: filepath
filepath: moduleFilepath
});
}
});
Expand Down
4 changes: 2 additions & 2 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ connection.onCompletion(async params => {

const IMPORT_REG = /import\s['"][a-zA-Z\._-]$/;
const IMPORT_FROM_REG = /import\s(([^\s]*)|(\*\sas\s[^\s]*))\sfrom\s['"][a-zA-Z\._-]$/;
const DYNAMIC_REG = /import\s*\(['"][a-zA-Z\._-]$/;
const DYNAMIC_REG = /import\s*\(['"][a-zA-Z\._-]['"]?$/;

const isImport =
IMPORT_REG.test(currentLine) || // import "https://xxxx.xxxx"
Expand All @@ -169,7 +169,7 @@ connection.onCompletion(async params => {
const deps = await deno.getDependencies();

const range = Range.create(
Position.create(position.line, position.character - 5),
Position.create(position.line, position.character),
position
);

Expand Down

0 comments on commit 055d062

Please sign in to comment.