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

Commit

Permalink
feat: remove lock std version and prefer HTTPS diagnostics. close
Browse files Browse the repository at this point in the history
…#33
  • Loading branch information
axetroy committed Feb 9, 2020
1 parent 34e6c10 commit 2480791
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 81 deletions.
65 changes: 25 additions & 40 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface DenoInfo {
}

interface ImportMap {
imports: { [key: string]: string };
imports: { [key: string]: string; };
}

function exists(filepath: string): Promise<boolean> {
Expand All @@ -87,7 +87,8 @@ async function getImportMaps(importMapFilepath: string, workspaceDir: string) {

try {
importMaps = JSON.parse(importMapContent.toString() || "{}");
} catch {}
} catch {
}
}
}

Expand Down Expand Up @@ -198,8 +199,7 @@ class Extension {
return;
}

outConfig[key] =
configSetting.workspaceFolderValue ??
outConfig[key] = configSetting.workspaceFolderValue ??
configSetting.workspaceValue ??
configSetting.globalValue;
}
Expand Down Expand Up @@ -255,7 +255,10 @@ class Extension {
await this.client.stop();
this.client = null;
}
const statusbar = window.createStatusBarItem(StatusBarAlignment.Left, -100);
const statusbar = window.createStatusBarItem(
StatusBarAlignment.Left,
-100
);
statusbar.text = `$(loading) ${localize("deno.initializing")}`;
statusbar.show();

Expand Down Expand Up @@ -352,8 +355,9 @@ class Extension {
});
client.onNotification("error", window.showErrorMessage);

client.onRequest("getWorkspaceFolder", async (uri: string) =>
workspace.getWorkspaceFolder(Uri.parse(uri))
client.onRequest(
"getWorkspaceFolder",
async (uri: string) => workspace.getWorkspaceFolder(Uri.parse(uri))
);

client.onRequest("getWorkspaceConfig", async (uri: string) => {
Expand Down Expand Up @@ -428,10 +432,9 @@ Executable ${this.denoInfo.executablePath}`;
}

const disabledFolders = folders.filter(
folder =>
!workspace
.getConfiguration(this.configurationSection, folder.uri)
.get("enable", true)
folder => !workspace
.getConfiguration(this.configurationSection, folder.uri)
.get("enable", true)
);

if (disabledFolders.length === 0) {
Expand Down Expand Up @@ -471,11 +474,9 @@ Executable ${this.denoInfo.executablePath}`;
return;
}

const enabledFolders = folders.filter(folder =>
workspace
.getConfiguration(this.configurationSection, folder.uri)
.get("enable", true)
);
const enabledFolders = folders.filter(folder => workspace
.getConfiguration(this.configurationSection, folder.uri)
.get("enable", true));

if (enabledFolders.length === 0) {
if (folders.length === 1) {
Expand Down Expand Up @@ -505,11 +506,8 @@ Executable ${this.denoInfo.executablePath}`;
}
// register quickly fix code action
private registerQuickFix(map: {
[command: string]: (
editor: TextEditor,
text: string,
range: Range
) => void | Promise<void>;
[command: string]: (editor: TextEditor, text: string, range: Range) => void
| Promise<void>;
}) {
for (let command in map) {
const handler = map[command];
Expand Down Expand Up @@ -571,11 +569,6 @@ Executable ${this.denoInfo.executablePath}`;
);

this.registerQuickFix({
_use_https_module: async (editor, text, range) => {
await editor.edit(e => {
e.replace(range, text.replace(/^http/, "https"));
});
},
_fetch_remote_module: async (editor, text) => {
const config = await this.getConfiguration(editor.document.uri);
const workspaceFolder = workspace.getWorkspaceFolder(
Expand Down Expand Up @@ -617,15 +610,17 @@ Executable ${this.denoInfo.executablePath}`;

if (extName === "") {
this.output.appendLine(
`Cannot create module \`${text}\` without specifying extension name`
`Cannot create module \`${text
}\` without specifying extension name`
);
this.output.show();
return;
}

if (text.indexOf(".") !== 0 && text.indexOf("/") !== 0) {
this.output.appendLine(
`Cannot create module \`${text}\`. Module is not relative or absolute`
`Cannot create module \`${text
}\`. Module is not relative or absolute`
);
this.output.show();
return;
Expand Down Expand Up @@ -653,17 +648,6 @@ Executable ${this.denoInfo.executablePath}`;
await fs.writeFile(absModuleFilepath, defaultTextContent);

this.updateDiagnostic(editor.document.uri);
},
_lock_std_version: (editor, text, range) => {
editor.edit(e =>
e.replace(
range,
text.replace(
"https://deno.land/std/",
`https://deno.land/std@v${this.denoInfo.version.deno}/`
)
)
);
}
});

Expand Down Expand Up @@ -697,7 +681,8 @@ Executable ${this.denoInfo.executablePath}`;

await this.StartDenoLanguageServer();

console.log(`Congratulations, your extension "vscode-deno" is now active!`);
console
.log(`Congratulations, your extension "vscode-deno" is now active!`);
}
// deactivate function for vscode
public async deactivate(context: ExtensionContext) {
Expand Down
42 changes: 1 addition & 41 deletions server/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,18 @@ interface Fix {
}

enum DiagnosticCode {
InvalidModule = 1001,
PreferHTTPS = 1003,
LocalModuleNotExist = 1004,
RemoteModuleNotExist = 1005,
LockStdVersion = 1006
RemoteModuleNotExist = 1005
}

const FixItems: { [code: number]: Fix; } = {
[DiagnosticCode.PreferHTTPS]: {
title: localize("diagnostic.fix.use_HTTPS_module"),
command: "deno._use_https_module"
},
[DiagnosticCode.LocalModuleNotExist]: {
title: localize("diagnostic.fix.create_module"),
command: "deno._create_local_module"
},
[DiagnosticCode.RemoteModuleNotExist]: {
title: localize("diagnostic.fix.fetch_module"),
command: "deno._fetch_remote_module"
},
[DiagnosticCode.LockStdVersion]: {
title: localize("diagnostic.fix.lock_std_version"),
command: "deno._lock_std_version"
}
};

Expand Down Expand Up @@ -228,35 +217,6 @@ export class Diagnostics {
document.positionAt(moduleNode.end)
);

const isRemoteModule = /^https?:\/\/.*/.test(moduleNode.text);

if (isRemoteModule) {
if (moduleNode.text.indexOf("https://") !== 0) {
diagnosticsForThisDocument.push(
Diagnostic.create(
range,
localize("diagnostic.report.use_HTTPS_module"),
DiagnosticSeverity.Warning,
DiagnosticCode.PreferHTTPS,
this.name
)
);
}

// if import module from deno_std
if (moduleNode.text.indexOf("https://deno.land/std/") === 0) {
diagnosticsForThisDocument.push(
Diagnostic.create(
range,
localize("diagnostic.report.lock_std_version"),
DiagnosticSeverity.Warning,
DiagnosticCode.LockStdVersion,
this.name
)
);
}
}

const module = await deno.resolveModule(
importMaps,
dir,
Expand Down

0 comments on commit 2480791

Please sign in to comment.