diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-19 08:06:48 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-19 08:06:48 +0000 |
commit | aca3c3086ee99f5770a60970e20af640c895d42a (patch) | |
tree | 2f0b3233cc4728436ba5e47a6e91e7df33585d43 /editors/code/src/util.ts | |
parent | 55336722b3662cbdcc9e1b92a3e27ed0442d2452 (diff) | |
parent | fb6e655de8a44c65275ad45a27bf5bd684670ba0 (diff) |
Merge #3629
3629: Alternative aproach to plugin auto update r=matklad a=matklad
This is very much WIP (as in, I haven't run this once), but I like the result so far.
cc @Veetaha
The primary focus here on simplification:
* local simplification of data structures and control-flow: using union of strings instead of an enum, using unwrapped GitHub API responses
* global simplification of control flow: all logic is now in `main.ts`, implemented as linear functions without abstractions. This is stateful side-effective code, so arguments from [Carmack](http://number-none.com/blow/john_carmack_on_inlined_code.html) very much apply. We need all user interractions, all mutations, and all network requests to happen in a single file.
* as a side-effect of condensing everything to functions, we can get rid of various enums. The enums were basically a reified control flow:
```
enum E { A, B }
fn foo() -> E {
if cond { E::A } else { E::B }
}
fn bar(e: E) {
match e {
E::A => do_a(),
E::B => do_b(),
}
}
==>>
fn all() {
if cond { do_a() } else { do_b() }
}
```
* simplification of model: we don't need to reinstall on settings update, we can just ask the user to reload, we don't need to handle nightly=>stable fallback, we can ask the user to reinstall extension, (todo) we don't need to parse out the date from the version, we can use build id for nightly and for stable we can write the info directly into package.json.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'editors/code/src/util.ts')
-rw-r--r-- | editors/code/src/util.ts | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts index 2bfc145e6..978a31751 100644 --- a/editors/code/src/util.ts +++ b/editors/code/src/util.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as lc from "vscode-languageclient"; | 1 | import * as lc from "vscode-languageclient"; |
2 | import * as vscode from "vscode"; | 2 | import * as vscode from "vscode"; |
3 | import { promises as dns } from "dns"; | ||
4 | import { strict as nativeAssert } from "assert"; | 3 | import { strict as nativeAssert } from "assert"; |
5 | 4 | ||
6 | export function assert(condition: boolean, explanation: string): asserts condition { | 5 | export function assert(condition: boolean, explanation: string): asserts condition { |
@@ -31,22 +30,6 @@ export const log = new class { | |||
31 | // eslint-disable-next-line no-console | 30 | // eslint-disable-next-line no-console |
32 | console.error(message, ...optionalParams); | 31 | console.error(message, ...optionalParams); |
33 | } | 32 | } |
34 | |||
35 | downloadError(err: Error, artifactName: string, repoName: string) { | ||
36 | vscode.window.showErrorMessage( | ||
37 | `Failed to download the rust-analyzer ${artifactName} from ${repoName} ` + | ||
38 | `GitHub repository: ${err.message}` | ||
39 | ); | ||
40 | log.error(err); | ||
41 | dns.resolve('example.com').then( | ||
42 | addrs => log.debug("DNS resolution for example.com was successful", addrs), | ||
43 | err => log.error( | ||
44 | "DNS resolution for example.com failed, " + | ||
45 | "there might be an issue with Internet availability", | ||
46 | err | ||
47 | ) | ||
48 | ); | ||
49 | } | ||
50 | }; | 33 | }; |
51 | 34 | ||
52 | export async function sendRequestWithRetry<TParam, TRet>( | 35 | export async function sendRequestWithRetry<TParam, TRet>( |
@@ -86,17 +69,6 @@ function sleep(ms: number) { | |||
86 | return new Promise(resolve => setTimeout(resolve, ms)); | 69 | return new Promise(resolve => setTimeout(resolve, ms)); |
87 | } | 70 | } |
88 | 71 | ||
89 | export function notReentrant<TThis, TParams extends any[], TRet>( | ||
90 | fn: (this: TThis, ...params: TParams) => Promise<TRet> | ||
91 | ): typeof fn { | ||
92 | let entered = false; | ||
93 | return function(...params) { | ||
94 | assert(!entered, `Reentrancy invariant for ${fn.name} is violated`); | ||
95 | entered = true; | ||
96 | return fn.apply(this, params).finally(() => entered = false); | ||
97 | }; | ||
98 | } | ||
99 | |||
100 | export type RustDocument = vscode.TextDocument & { languageId: "rust" }; | 72 | export type RustDocument = vscode.TextDocument & { languageId: "rust" }; |
101 | export type RustEditor = vscode.TextEditor & { document: RustDocument; id: string }; | 73 | export type RustEditor = vscode.TextEditor & { document: RustDocument; id: string }; |
102 | 74 | ||
@@ -110,29 +82,3 @@ export function isRustDocument(document: vscode.TextDocument): document is RustD | |||
110 | export function isRustEditor(editor: vscode.TextEditor): editor is RustEditor { | 82 | export function isRustEditor(editor: vscode.TextEditor): editor is RustEditor { |
111 | return isRustDocument(editor.document); | 83 | return isRustDocument(editor.document); |
112 | } | 84 | } |
113 | |||
114 | /** | ||
115 | * @param extensionId The canonical extension identifier in the form of: `publisher.name` | ||
116 | */ | ||
117 | export async function vscodeReinstallExtension(extensionId: string) { | ||
118 | // Unfortunately there is no straightforward way as of now, these commands | ||
119 | // were found in vscode source code. | ||
120 | |||
121 | log.debug("Uninstalling extension", extensionId); | ||
122 | await vscode.commands.executeCommand("workbench.extensions.uninstallExtension", extensionId); | ||
123 | log.debug("Installing extension", extensionId); | ||
124 | await vscode.commands.executeCommand("workbench.extensions.installExtension", extensionId); | ||
125 | } | ||
126 | |||
127 | export async function vscodeReloadWindow(): Promise<never> { | ||
128 | await vscode.commands.executeCommand("workbench.action.reloadWindow"); | ||
129 | |||
130 | assert(false, "unreachable"); | ||
131 | } | ||
132 | |||
133 | export async function vscodeInstallExtensionFromVsix(vsixPath: string) { | ||
134 | await vscode.commands.executeCommand( | ||
135 | "workbench.extensions.installExtension", | ||
136 | vscode.Uri.file(vsixPath) | ||
137 | ); | ||
138 | } | ||