Skip to content

Commit

Permalink
Add stylua.disableVersionCheck (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyMorganz authored Jun 25, 2022
1 parent e59603b commit 8073ac6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 29 deletions.
4 changes: 4 additions & 0 deletions stylua-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ To view the changelog of the StyLua binary, see [here](https://github.com/Johnny

## [Unreleased]

### Added

- Added `stylua.disableVersionCheck` to configure whether we call out to GitHub to check for newer versions. Useful if you do not want network requests

## [1.3.2] - 2022-03-07

### Changed
Expand Down
5 changes: 5 additions & 0 deletions stylua-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
],
"default": null,
"description": "Specifies the path of StyLua. If not specified, will automatically download one from the GitHub releases."
},
"stylua.disableVersionCheck": {
"type": "boolean",
"default": false,
"description": "Disable checking the version of stylua for newer versions. Useful if you do not want network requests"
}
}
}
Expand Down
62 changes: 33 additions & 29 deletions stylua-vscode/src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,40 @@ export class StyluaDownloader {
return;
}

try {
const currentVersion = (
await executeStylua(path, ["--version"])
)?.trim();
const desiredVersion = util.getDesiredVersion();
const release = await this.github.getRelease(desiredVersion);
if (
currentVersion !==
`stylua ${
release.tagName.startsWith("v")
? release.tagName.substr(1)
: release.tagName
}`
) {
this.openUpdatePrompt(release);
}
} catch (err) {
vscode.window.showWarningMessage(
`Error checking the selected StyLua version, falling back to the currently installed version:\n${err}`
);
if (!this.github.authenticated) {
const option = await vscode.window.showInformationMessage(
"Authenticating with GitHub can fix rate limits.",
"Authenticate with GitHub"
if (
!vscode.workspace.getConfiguration("stylua").get("disableVersionCheck")
) {
try {
const currentVersion = (
await executeStylua(path, ["--version"])
)?.trim();
const desiredVersion = util.getDesiredVersion();
const release = await this.github.getRelease(desiredVersion);
if (
currentVersion !==
`stylua ${
release.tagName.startsWith("v")
? release.tagName.substr(1)
: release.tagName
}`
) {
this.openUpdatePrompt(release);
}
} catch (err) {
vscode.window.showWarningMessage(
`Error checking the selected StyLua version, falling back to the currently installed version:\n${err}`
);
switch (option) {
case "Authenticate with GitHub":
if (await this.github.authenticate()) {
return this.ensureStyluaExists();
}
if (!this.github.authenticated) {
const option = await vscode.window.showInformationMessage(
"Authenticating with GitHub can fix rate limits.",
"Authenticate with GitHub"
);
switch (option) {
case "Authenticate with GitHub":
if (await this.github.authenticate()) {
return this.ensureStyluaExists();
}
}
}
}
}
Expand Down

0 comments on commit 8073ac6

Please sign in to comment.