-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove the initial setup with automatic Zig version management
This commit replaces the initial setup with the following mechanism: 1. If the workspace contains a `.zigversion`, install the given Zig version. 2. If the workspace contains a `build.zig.zon` with a `minimum_zig_version`, install the next available Zig version. 3. Check if the "Install Zig" has been previously executed in the active workspace. If so, install that version. 3. Otherwise fallback to the latest tagged release of Zig. Some parts of this are not fully implemented. fixes #111
- Loading branch information
Showing
7 changed files
with
277 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import vscode from "vscode"; | ||
|
||
import semver from "semver"; | ||
|
||
import { resolveExePathAndVersion } from "./zigUtil"; | ||
|
||
export interface ExeWithVersion { | ||
exe: string; | ||
version: semver.SemVer; | ||
} | ||
|
||
export class ZigProvider implements vscode.Disposable { | ||
onChange: vscode.EventEmitter<ExeWithVersion | null> = new vscode.EventEmitter(); | ||
private value: ExeWithVersion | null = null; | ||
private disposables: vscode.Disposable[]; | ||
|
||
constructor() { | ||
this.disposables = [ | ||
vscode.workspace.onDidChangeConfiguration((change) => { | ||
if (change.affectsConfiguration("zig.path")) { | ||
this.set(this.getZig()); | ||
} | ||
}), | ||
]; | ||
} | ||
|
||
/** Returns the path and version of the Zig executable that is currently being used. */ | ||
public getZig(): ExeWithVersion | null { | ||
const configuration = vscode.workspace.getConfiguration("zig"); | ||
const zigPath = configuration.get<string>("path", ""); | ||
if (!!zigPath) { | ||
const exePath = zigPath !== "zig" ? zigPath : null; // the string "zig" means lookup in PATH | ||
const result = resolveExePathAndVersion(exePath, "zig", "zig.path", "version"); | ||
if ("message" in result) { | ||
void vscode.window.showErrorMessage(`'zig.path' is not valid: ${result.message}`); | ||
return null; | ||
} | ||
return result; | ||
} | ||
|
||
return this.value; | ||
} | ||
|
||
/** Returns the version of the Zig executable that is currently being used. */ | ||
public getZigVersion(): semver.SemVer | null { | ||
const result = this.getZig(); | ||
if (!result) return null; | ||
return result.version; | ||
} | ||
|
||
/** Returns the path to the Zig executable that is currently being used. */ | ||
public getZigPath(): string | null { | ||
const result = this.getZig(); | ||
if (!result) return null; | ||
return result.exe; | ||
} | ||
|
||
/** Override which zig executable should be used. The `zig.path` config option will be ignored */ | ||
public set(value: ExeWithVersion | null) { | ||
this.value = value; | ||
this.onChange.fire(value); | ||
} | ||
|
||
dispose() { | ||
for (const disposable of this.disposables) { | ||
disposable.dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.