diff options
author | Veetaha <[email protected]> | 2020-02-08 22:27:04 +0000 |
---|---|---|
committer | Veetaha <[email protected]> | 2020-02-08 22:27:04 +0000 |
commit | 539daf4454e3f11424a469e8fba26cacb325176a (patch) | |
tree | 28f37d3adbfedc75b9d4cf25d50ab20469f48cf3 /editors/code/src/installation | |
parent | bdd88c2fad272f96a8212e5230010f7c02b4d15d (diff) |
vscode: refactor platform artifact name query to switch statement, move BinarySource union variants into a namespace
Diffstat (limited to 'editors/code/src/installation')
-rw-r--r-- | editors/code/src/installation/interfaces.ts | 58 | ||||
-rw-r--r-- | editors/code/src/installation/language_server.ts | 10 |
2 files changed, 35 insertions, 33 deletions
diff --git a/editors/code/src/installation/interfaces.ts b/editors/code/src/installation/interfaces.ts index 03eac5b79..8039d0b90 100644 --- a/editors/code/src/installation/interfaces.ts +++ b/editors/code/src/installation/interfaces.ts | |||
@@ -12,42 +12,44 @@ export interface ArtifactMetadata { | |||
12 | } | 12 | } |
13 | 13 | ||
14 | /** | 14 | /** |
15 | * Type tag for `BinarySource` discriminated union. | ||
16 | */ | ||
17 | export enum BinarySourceType { ExplicitPath, GithubBinary } | ||
18 | |||
19 | /** | ||
20 | * Represents the source of a binary artifact which is either specified by the user | 15 | * Represents the source of a binary artifact which is either specified by the user |
21 | * explicitly, or bundled by this extension from GitHub releases. | 16 | * explicitly, or bundled by this extension from GitHub releases. |
22 | */ | 17 | */ |
23 | export type BinarySource = ExplicitPathSource | GithubBinarySource; | 18 | export type BinarySource = BinarySource.ExplicitPath | BinarySource.GithubRelease; |
24 | |||
25 | |||
26 | export interface ExplicitPathSource { | ||
27 | type: BinarySourceType.ExplicitPath; | ||
28 | 19 | ||
20 | export namespace BinarySource { | ||
29 | /** | 21 | /** |
30 | * Filesystem path to the binary specified by the user explicitly. | 22 | * Type tag for `BinarySource` discriminated union. |
31 | */ | 23 | */ |
32 | path: string; | 24 | export const enum Type { ExplicitPath, GithubRelease } |
33 | } | ||
34 | 25 | ||
35 | export interface GithubBinarySource { | 26 | export interface ExplicitPath { |
36 | type: BinarySourceType.GithubBinary; | 27 | type: Type.ExplicitPath; |
37 | 28 | ||
38 | /** | 29 | /** |
39 | * Repository where the binary is stored. | 30 | * Filesystem path to the binary specified by the user explicitly. |
40 | */ | 31 | */ |
41 | repo: GithubRepo; | 32 | path: string; |
33 | } | ||
42 | 34 | ||
43 | /** | 35 | export interface GithubRelease { |
44 | * Directory on the filesystem where the bundled binary is stored. | 36 | type: Type.GithubRelease; |
45 | */ | 37 | |
46 | dir: string; | 38 | /** |
39 | * Repository where the binary is stored. | ||
40 | */ | ||
41 | repo: GithubRepo; | ||
42 | |||
43 | /** | ||
44 | * Directory on the filesystem where the bundled binary is stored. | ||
45 | */ | ||
46 | dir: string; | ||
47 | |||
48 | /** | ||
49 | * Name of the binary file. It is stored under the same name on GitHub releases | ||
50 | * and in local `.dir`. | ||
51 | */ | ||
52 | file: string; | ||
53 | } | ||
47 | 54 | ||
48 | /** | ||
49 | * Name of the binary file. It is stored under the same name on GitHub releases | ||
50 | * and in local `.dir`. | ||
51 | */ | ||
52 | file: string; | ||
53 | } | 55 | } |
diff --git a/editors/code/src/installation/language_server.ts b/editors/code/src/installation/language_server.ts index b75d3a00a..522d59eb5 100644 --- a/editors/code/src/installation/language_server.ts +++ b/editors/code/src/installation/language_server.ts | |||
@@ -5,12 +5,12 @@ import * as path from "path"; | |||
5 | import { strict as assert } from "assert"; | 5 | import { strict as assert } from "assert"; |
6 | import { promises as fs } from "fs"; | 6 | import { promises as fs } from "fs"; |
7 | 7 | ||
8 | import { BinarySource, BinarySourceType, GithubBinarySource } from "./interfaces"; | 8 | import { BinarySource } from "./interfaces"; |
9 | import { fetchLatestArtifactMetadata } from "./fetch_latest_artifact_metadata"; | 9 | import { fetchLatestArtifactMetadata } from "./fetch_latest_artifact_metadata"; |
10 | import { downloadFile } from "./download_file"; | 10 | import { downloadFile } from "./download_file"; |
11 | 11 | ||
12 | export async function downloadLatestLanguageServer( | 12 | export async function downloadLatestLanguageServer( |
13 | {file: artifactFileName, dir: installationDir, repo}: GithubBinarySource | 13 | {file: artifactFileName, dir: installationDir, repo}: BinarySource.GithubRelease |
14 | ) { | 14 | ) { |
15 | const binaryMetadata = await fetchLatestArtifactMetadata(repo, artifactFileName); | 15 | const binaryMetadata = await fetchLatestArtifactMetadata(repo, artifactFileName); |
16 | 16 | ||
@@ -67,7 +67,7 @@ export async function ensureLanguageServerBinary( | |||
67 | } | 67 | } |
68 | 68 | ||
69 | switch (langServerSource.type) { | 69 | switch (langServerSource.type) { |
70 | case BinarySourceType.ExplicitPath: { | 70 | case BinarySource.Type.ExplicitPath: { |
71 | if (isBinaryAvailable(langServerSource.path)) { | 71 | if (isBinaryAvailable(langServerSource.path)) { |
72 | return langServerSource.path; | 72 | return langServerSource.path; |
73 | } | 73 | } |
@@ -78,7 +78,7 @@ export async function ensureLanguageServerBinary( | |||
78 | ); | 78 | ); |
79 | return null; | 79 | return null; |
80 | } | 80 | } |
81 | case BinarySourceType.GithubBinary: { | 81 | case BinarySource.Type.GithubRelease: { |
82 | const bundledBinaryPath = path.join(langServerSource.dir, langServerSource.file); | 82 | const bundledBinaryPath = path.join(langServerSource.dir, langServerSource.file); |
83 | 83 | ||
84 | if (!isBinaryAvailable(bundledBinaryPath)) { | 84 | if (!isBinaryAvailable(bundledBinaryPath)) { |
@@ -106,7 +106,7 @@ export async function ensureLanguageServerBinary( | |||
106 | ); | 106 | ); |
107 | 107 | ||
108 | vscode.window.showInformationMessage( | 108 | vscode.window.showInformationMessage( |
109 | "Rust analyzer language server was successfully installed" | 109 | "Rust analyzer language server was successfully installed 🦀" |
110 | ); | 110 | ); |
111 | } | 111 | } |
112 | return bundledBinaryPath; | 112 | return bundledBinaryPath; |