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

Commit

Permalink
release v1.21.0
Browse files Browse the repository at this point in the history
Signed-off-by: 迷渡 <[email protected]>
  • Loading branch information
justjavac committed May 13, 2020
1 parent 7b0b601 commit 8efdc49
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-deno-plugin",
"version": "1.18.0",
"version": "1.21.0",
"description": "Deno language service plugin for TypeScript",
"main": "out/index.js",
"types": "out/index.d.ts",
Expand Down
30 changes: 23 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const config: DenoPluginConfig = {
enable: true,
};

let parsedImportMap: ImportMaps | null = null;
let projectDirectory: string;

module.exports = function init(
{ typescript }: { typescript: typeof ts_module },
) {
Expand Down Expand Up @@ -84,12 +87,10 @@ module.exports = function init(
return tsLs;
}

const projectDirectory = project.getCurrentDirectory();
projectDirectory = project.getCurrentDirectory();
// TypeScript plugins have a `cwd` of `/`, which causes issues with import resolution.
process.chdir(projectDirectory);

let parsedImportMap: ImportMaps | null = null;

const resolveTypeReferenceDirectives =
tsLsHost.resolveTypeReferenceDirectives;

Expand Down Expand Up @@ -126,6 +127,7 @@ module.exports = function init(
containingFile: string,
...rest
) => {
logger.info("resolveModuleNames");
if (!config.enable) {
logger.info("plugin disabled.");
return resolveModuleNames.call(
Expand Down Expand Up @@ -155,17 +157,21 @@ module.exports = function init(
);

if (parsedModuleName == null) {
logger.info(`module "${moduleName}" can not parsed`)
resolvedModules.push(undefined);
continue;
}

const resolvedModule = resolveDenoModule(parsedModuleName);

if (!resolvedModule) {
logger.info(`module "${moduleName}" can not resolved`)
resolvedModules.push(undefined);
continue;
}

logger.info(`module "${moduleName}" -> ${resolvedModule.filepath}`);

resolvedModules.push({
extension: resolvedModule.extension as ts_module.Extension,
isExternalLibraryImport: false,
Expand Down Expand Up @@ -297,6 +303,7 @@ module.exports = function init(
}

function getSemanticDiagnostics(filename: string) {
logger.info("getSemanticDiagnostics");
const diagnostics = tsLs.getSemanticDiagnostics(filename);

if (!config.enable) {
Expand Down Expand Up @@ -359,7 +366,7 @@ module.exports = function init(
);

if (parsedModuleName == null) {
d.code = 10001;
d.code = 10001; // InvalidRelativeImport
d.messageText =
`relative import path "${moduleName}" not prefixed with / or ./ or ../`;
return d;
Expand All @@ -373,7 +380,7 @@ module.exports = function init(

if (isHttpURL(parsedModuleName)) {
d.code = 10002; // RemoteModuleNotExist
d.messageText = `Could not find module ${moduleName} locally`;
d.messageText = `The remote module "${moduleName}" have not cached locally`;
return d;
}

Expand All @@ -384,11 +391,11 @@ module.exports = function init(
parsedModuleName.startsWith("file://")
) {
d.code = 10003; // LocalModuleNotExist
d.messageText = `Could not find module ${moduleName} locally`;
d.messageText = `Could not find module "${moduleName}" locally`;
return d;
}

d.code = 10003; // InvalidImport
d.code = 10004; // InvalidImport
d.messageText =
`Import module "${moduleName}" must be a relative path or remote HTTP URL`;
}
Expand All @@ -411,9 +418,18 @@ module.exports = function init(
onConfigurationChanged(c: DenoPluginConfig) {
logger.info("config change to:\n" + JSON.stringify(c, null, " "));
Object.assign(config, c);

if (config.importmap != null) {
parsedImportMap = parseImportMapFromFile(
projectDirectory,
config.importmap,
);
}

pluginInfo.project.markAsDirty();
pluginInfo.project.refreshDiagnostics();
pluginInfo.project.updateGraph();
pluginInfo.languageService.getProgram()?.emit();
},
};
};
Expand Down

0 comments on commit 8efdc49

Please sign in to comment.