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

Commit

Permalink
feat: add diagnostic for checking valid import statement
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Mar 27, 2020
1 parent 0e8398f commit b2f070a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package.de-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"err.below_deno_minimum_requirements": "Deno's version is below minimum requirements. Please upgrade to v{0} or above.",
"diagnostic.fix.create_module": "Erstellen das Modul",
"diagnostic.fix.fetch_module": "Download das Modul",
"diagnostic.report.module_not_found_locally": "Modul `{0}` konnte lokal nicht gefunden werden."
"diagnostic.report.module_not_found_locally": "Modul `{0}` konnte lokal nicht gefunden werden.",
"diagnostic.report.invalid_import": "Import module `{0}` must be a relative path or remote HTTP URL."
}
3 changes: 2 additions & 1 deletion package.nl-nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"err.below_deno_minimum_requirements": "Deno's version is below minimum requirements. Please upgrade to v{0} or above.",
"diagnostic.fix.create_module": "Maak de module",
"diagnostic.fix.fetch_module": "Download de module",
"diagnostic.report.module_not_found_locally": "Kan module `{0}` niet lokaal vinden."
"diagnostic.report.module_not_found_locally": "Kan module `{0}` niet lokaal vinden.",
"diagnostic.report.invalid_import": "Import module `{0}` must be a relative path or remote HTTP URL."
}
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"err.below_deno_minimum_requirements": "Deno's version is below minimum requirements. Please upgrade to v{0} or above.",
"diagnostic.fix.create_module": "Create the module",
"diagnostic.fix.fetch_module": "Fetch the module",
"diagnostic.report.module_not_found_locally": "Could not find module `{0}` locally."
"diagnostic.report.module_not_found_locally": "Could not find module `{0}` locally.",
"diagnostic.report.invalid_import": "Import module `{0}` must be a relative path or remote HTTP URL."
}
3 changes: 2 additions & 1 deletion package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"err.below_deno_minimum_requirements": "Deno 的版本低于最小要求。 请升级至 v{0} 或以上。",
"diagnostic.fix.create_module": "创建模块。",
"diagnostic.fix.fetch_module": "拉取模块。",
"diagnostic.report.module_not_found_locally": "找不到模块 `{0}`。"
"diagnostic.report.module_not_found_locally": "找不到模块 `{0}`。",
"diagnostic.report.invalid_import": "导入模块 `{0}` 必须是一个相对路径或者 HTTP 的 URL"
}
3 changes: 2 additions & 1 deletion package.nls.zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"err.below_deno_minimum_requirements": "Deno 的版本低於最小要求。請升級至 v{0} 或以上。",
"diagnostic.fix.create_module": "创建模块。",
"diagnostic.fix.fetch_module": "創建模塊。",
"diagnostic.report.module_not_found_locally": "找不到模塊 `{0}`。"
"diagnostic.report.module_not_found_locally": "找不到模塊 `{0}`。",
"diagnostic.report.invalid_import": "導入模塊 `{0}` 必須是一個相對路徑或者 HTTP 的 URL"
}
47 changes: 43 additions & 4 deletions server/src/language/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Fix = {
};

enum DiagnosticCode {
InvalidImport = 1000,
LocalModuleNotExist = 1004,
RemoteModuleNotExist = 1005,
}
Expand Down Expand Up @@ -158,14 +159,52 @@ export class Diagnostics {
: ImportMap.create(importMapFilepath).resolveModule(
importModule.moduleName
);

if (isHttpURL(moduleName)) {
diagnosticsForThisDocument.push(
Diagnostic.create(
importModule.location,
localize(
"diagnostic.report.module_not_found_locally",
moduleName
),
DiagnosticSeverity.Error,
DiagnosticCode.RemoteModuleNotExist,
this.name
)
);
continue;
}

console.log(moduleName);

if (
path.isAbsolute(moduleName) ||
moduleName.startsWith(".") ||
moduleName.startsWith("file://")
) {
diagnosticsForThisDocument.push(
Diagnostic.create(
importModule.location,
localize(
"diagnostic.report.module_not_found_locally",
moduleName
),
DiagnosticSeverity.Error,
DiagnosticCode.LocalModuleNotExist,
this.name
)
);
continue;
}

// invalid module
diagnosticsForThisDocument.push(
Diagnostic.create(
importModule.location,
localize("diagnostic.report.module_not_found_locally", moduleName),
localize("diagnostic.report.invalid_import", moduleName),
DiagnosticSeverity.Error,
isHttpURL(moduleName)
? DiagnosticCode.RemoteModuleNotExist
: DiagnosticCode.LocalModuleNotExist,
DiagnosticCode.InvalidImport,
this.name
)
);
Expand Down

0 comments on commit b2f070a

Please sign in to comment.