Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update from upstream #4

Merged
merged 6 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ coverage
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/cache

# misc
.DS_Store
Expand Down
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"name": "Attach to Server",
"port": 9523,
"restart": true,
"outFiles": ["${workspaceRoot}/server/out/**/*.js"]
"outFiles": ["${workspaceRoot}/server/out/**/*.js"],
"sourceMaps": true
},
{
"name": "Language Server E2E Test",
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ Features:

</details>

<details><summary>Intelligent module import enhanced</summary>

![Import enhanced](screenshot/import_enhancement.gif)

</details>

<details><summary>Supports importing ECMAScript modules</summary>

![Import](screenshot/ecma.gif)
Expand Down Expand Up @@ -133,6 +139,8 @@ console.log("concat Array", M.concat([1, 2], [2, 3]));

- `deno.unstable` - If Deno's unstable mode is enabled. Default is `false`

- `deno.lint` - If inline `deno lint` diagnostics are enabled. Because this is experimental, `deno.unstable = true` is required. Default is `false`

We recommend that you do not set global configuration. It should be configured in `.vscode/settings.json` in the project directory:

```json5
Expand All @@ -158,6 +166,19 @@ This extension also provides Deno's formatting tools, settings are in `.vscode/s
}
```

This extension also provides inline `deno lint` diagnostics. You can enable this in `.vscode/settings.json`:

NOTE: Since `deno lint` is still an experimental feature, you need to set `deno.unstable = true` in your VS Code settings. This function may change in the future.

```json5
// .vscode/settings.json
{
"deno.enable": true,
"deno.unstable": true,
"deno.lint": true,
}
```

## Contribute

Follow these steps to contribute, the community needs your strength.
Expand Down
6 changes: 6 additions & 0 deletions Releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Releases of the extension can be downloaded from [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno).

### [v2.2.0](https://github.com/denoland/vscode_deno/compare/v2.1.2...v2.2.0) / 2020.09.07

- feat: add inline `deno lint` diagnostics (#162)
- fix: add IntelliSense support for `export` (#184)
- refactor: move imports IntelliSense logic to server (#181)

### [v2.1.2](https://github.com/denoland/vscode_deno/compare/v2.1.1...v2.1.2) / 2020.09.04

- fix: another typescript not found error (#178)
Expand Down
137 changes: 76 additions & 61 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
TextDocument,
languages,
env,
Position,
} from "vscode";
import {
LanguageClient,
Expand All @@ -29,14 +30,8 @@ import {
} from "vscode-languageclient";
import getport from "get-port";
import execa from "execa";
import * as semver from "semver";

import { TreeViewProvider } from "./tree_view_provider";
import {
ImportEnhancementCompletionProvider,
CACHE_STATE,
} from "./import_enhancement_provider";

import { ImportMap } from "../../core/import_map";
import { HashMeta } from "../../core/hash_meta";
import { isInDeno } from "../../core/deno";
Expand Down Expand Up @@ -118,9 +113,6 @@ export class Extension {
},
executablePath: "",
};
// CGQAQ: ImportEnhancementCompletionProvider instance
private import_enhancement_completion_provider = new ImportEnhancementCompletionProvider();

// get configuration of Deno
public getConfiguration(uri?: Uri): ConfigurationField {
const config: ConfigurationField = {};
Expand Down Expand Up @@ -244,7 +236,10 @@ export class Extension {
}
const denoDiagnostics: Diagnostic[] = [];
for (const diagnostic of context.diagnostics) {
if (diagnostic.source === "Deno Language Server") {
if (
diagnostic.source === "Deno Language Server" ||
diagnostic.source === "deno_lint"
) {
denoDiagnostics.push(diagnostic);
}
}
Expand Down Expand Up @@ -356,29 +351,39 @@ Executable ${this.denoInfo.executablePath}`;
[command: string]: (
editor: TextEditor,
text: string,
range: Range
range: Range,
...args: unknown[]
) => void | Promise<void>;
}) {
for (const command in map) {
const handler = map[command];
this.registerCommand(command, async (uri: string, range: Range) => {
const textEditor = window.activeTextEditor;
this.registerCommand(
command,
async (uri: string, range: Range, ...args: unknown[]) => {
const textEditor = window.activeTextEditor;

if (!textEditor || textEditor.document.uri.toString() !== uri) {
return;
}
if (!textEditor || textEditor.document.uri.toString() !== uri) {
return;
}

range = new Range(
range.start.line,
range.start.character,
range.end.line,
range.end.character
);
range = new Range(
range.start.line,
range.start.character,
range.end.line,
range.end.character
);

const rangeText = textEditor.document.getText(range);
const rangeText = textEditor.document.getText(range);

return await handler.call(this, textEditor, rangeText, range);
});
return await handler.call(
this,
textEditor,
rangeText,
range,
...args
);
}
);
}
}
// update diagnostic for a Document
Expand Down Expand Up @@ -473,14 +478,6 @@ Executable ${this.denoInfo.executablePath}`;
await window.showInformationMessage(`Copied to clipboard.`);
});

// CGQAQ: deno._clear_import_enhencement_cache
this.registerCommand("_clear_import_enhencement_cache", async () => {
this.import_enhancement_completion_provider
.clearCache()
.then(() => window.showInformationMessage("Clear success!"))
.catch(() => window.showErrorMessage("Clear failed!"));
});

this.registerQuickFix({
_fetch_remote_module: async (editor, text) => {
const config = this.getConfiguration(editor.document.uri);
Expand Down Expand Up @@ -511,22 +508,25 @@ Executable ${this.denoInfo.executablePath}`;
cancellable: true,
},
(process, cancelToken) => {
// `deno fetch xxx` has been renamed to `deno cache xxx` since Deno v0.40.0
const cmd = semver.gte(this.denoInfo.version.deno, "0.40.0")
? "cache"
: "fetch";
const ps = execa(this.denoInfo.executablePath, [cmd, moduleName], {
// timeout of 2 minute
timeout: 1000 * 60 * 2,
});
const ps = execa(
this.denoInfo.executablePath,
["cache", moduleName],
{
// timeout of 2 minute
timeout: 1000 * 60 * 2,
env: {
NO_COLOR: "1",
},
}
);

const updateProgress: (buf: Buffer) => void = (buf: Buffer) => {
const raw = buf.toString();

const messages = raw.split("\n");

for (let message of messages) {
message = message.replace("[0mDownload", "").trim();
message = message.replace("Download", "").trim();
if (message) {
process.report({ message });
this.output.appendLine(message);
Expand Down Expand Up @@ -596,6 +596,40 @@ Executable ${this.denoInfo.executablePath}`;

this.updateDiagnostic(editor.document.uri);
},
_ignore_next_line_lint: async (editor, _, range, rule: unknown) => {
editor.edit((edit) => {
const currentLineText = editor.document.lineAt(range.start.line);
const previousLineText = editor.document.lineAt(range.start.line - 1);

const offset =
currentLineText.text.length - currentLineText.text.trim().length;

if (/^\s*\/\/\s+deno-lint-ignore\s*/.test(previousLineText.text)) {
edit.replace(
previousLineText.range,
previousLineText.text + " " + rule
);
} else {
edit.replace(
previousLineText.range,
previousLineText.text +
"\n" +
`${" ".repeat(offset)}// deno-lint-ignore ${rule}`
);
}
});
return;
},
_ignore_entry_file: async (editor) => {
editor.edit((edit) => {
const firstLineText = editor.document.lineAt(0);
edit.insert(
new Position(0, 0),
"// deno-lint-ignore-file" + (firstLineText.text ? "\n" : "")
);
});
return;
},
});

this.watchConfiguration(() => {
Expand All @@ -611,23 +645,6 @@ Executable ${this.denoInfo.executablePath}`;
window.registerTreeDataProvider("deno", treeView)
);

// CGQAQ: activate import enhance feature
this.import_enhancement_completion_provider.activate(this.context);

// CGQAQ: Start caching full module list
this.import_enhancement_completion_provider
.cacheModList()
.then((state) => {
if (state === CACHE_STATE.CACHE_SUCCESS) {
window.showInformationMessage(
"deno.land/x module list cached successfully!"
);
}
})
.catch(() =>
window.showErrorMessage("deno.land/x module list failed to cache!")
);

this.sync(window.activeTextEditor?.document);

const extension = extensions.getExtension(this.id);
Expand All @@ -640,8 +657,6 @@ Executable ${this.denoInfo.executablePath}`;
public async deactivate(context: ExtensionContext): Promise<void> {
this.context = context;

this.import_enhancement_completion_provider.dispose();

if (this.client) {
await this.client.stop();
this.client = undefined;
Expand Down
Loading