-
Notifications
You must be signed in to change notification settings - Fork 3
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 version prompt if l2 binary below v1.5.1 #11
Changes from 4 commits
212a5fa
b6d577a
2e9f2a0
d8060b2
5f40c3e
c83bb16
ab70a59
bb6bd24
9152b41
e2a7a66
d69f38a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 6, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
"@typescript-eslint/naming-convention": "warn", | ||
"@typescript-eslint/semi": "warn", | ||
"curly": "warn", | ||
"eqeqeq": "warn", | ||
"no-throw-literal": "warn", | ||
"semi": "off" | ||
}, | ||
"ignorePatterns": [ | ||
"out", | ||
"dist", | ||
"**/*.d.ts" | ||
] | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 6, | ||
"sourceType": "module" | ||
}, | ||
"plugins": ["@typescript-eslint"], | ||
"rules": { | ||
"@typescript-eslint/naming-convention": "warn", | ||
"@typescript-eslint/semi": "warn", | ||
"curly": "warn", | ||
"eqeqeq": "warn", | ||
"no-throw-literal": "warn", | ||
"semi": "off" | ||
}, | ||
"ignorePatterns": ["out", "dist", "**/*.d.ts"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,36 @@ | ||
{ | ||
"name": "l2", | ||
"displayName": "l2", | ||
"description": "Utilties and support for working with Lama2", | ||
"version": "0.0.1", | ||
"engines": { | ||
"vscode": "^1.65.0" | ||
}, | ||
"categories": [ | ||
"Programming Languages" | ||
"name": "l2", | ||
"displayName": "l2", | ||
"description": "Utilties and support for working with Lama2", | ||
"version": "0.0.1", | ||
"engines": { | ||
"vscode": "^1.65.0" | ||
}, | ||
"categories": [ | ||
"Programming Languages" | ||
], | ||
"contributes": { | ||
"languages": [ | ||
{ | ||
"id": "l2", | ||
"aliases": [ | ||
"l2", | ||
"lama2" | ||
], | ||
"extensions": [ | ||
".l2", | ||
".lama", | ||
".lama2" | ||
], | ||
"configuration": "./language-configuration.json" | ||
} | ||
], | ||
"contributes": { | ||
"languages": [{ | ||
"id": "l2", | ||
"aliases": ["l2", "lama2"], | ||
"extensions": [".l2", ".lama", ".lama2"], | ||
"configuration": "./language-configuration.json" | ||
}], | ||
"grammars": [{ | ||
"language": "lama2", | ||
"scopeName": "source.http", | ||
"path": "./syntaxes/http.tmLanguage.json" | ||
}] | ||
} | ||
} | ||
"grammars": [ | ||
{ | ||
"language": "lama2", | ||
"scopeName": "source.http", | ||
"path": "./syntaxes/http.tmLanguage.json" | ||
} | ||
] | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
trailingComma: "es5", | ||
tabWidth: 2, | ||
semi: false, | ||
singleQuote: false, | ||
arrowParens: "always", | ||
useTabs: false, | ||
printWidth: 120, // Add line length here (e.g., 80) | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,35 @@ | ||
import { exec } from "child_process"; | ||
import { exec, execSync } from "child_process"; | ||
import * as semver from "semver"; | ||
import * as vscode from "vscode"; | ||
import { getShowLama2Term } from "./utils"; | ||
|
||
const MIN_VERSION_TO_CHECK = "1.5.2"; | ||
const LAMA2_TERM_NAME = "AutoLama2"; | ||
const UPDATE_MSG = "Support for environment variables."; | ||
|
||
export function checkL2Version() { | ||
export async function getL2VersionAndUpdatePrompt(minVersionToCheck: string) { | ||
try { | ||
getL2Version((l2Version) => { | ||
// Check if version is below MIN_VERSION_TO_CHECK | ||
if (compareL2Versions(l2Version, MIN_VERSION_TO_CHECK) < 0) { | ||
showUpdateWarning(); | ||
const l2Version = execSync("l2 --version", { encoding: 'utf-8' }).trim(); | ||
// Use the semver library to validate and normalize the version string | ||
const normalizedVersion = semver.valid(l2Version); | ||
if (normalizedVersion) { | ||
|
||
if (semver.lt(l2Version, minVersionToCheck)) { | ||
showUpdateWarning(minVersionToCheck); | ||
} | ||
}); | ||
return normalizedVersion; | ||
} else { | ||
throw new Error("Invalid version format: " + l2Version); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we report to the user - that the version is unknown and probably the extension will not work in full? We can have a button "Download" to direct them to website. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this |
||
} | ||
} catch (e: any) { | ||
console.log("Problem while checking for version -> ", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should surface this as a warning - I think. Especially - what happens when there is no binary in the path? I think the user ought to know that something is wrong, and that action is needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah added |
||
} | ||
} | ||
|
||
function getL2Version(callback: (version: string) => void) { | ||
exec("l2 --version", (error, stdout, stderr) => { | ||
const versionOutput = stdout.trim(); | ||
const versionMatch = versionOutput.match(/v(\d+\.\d+\.\d+)/); | ||
if (versionMatch && versionMatch.length === 2) { | ||
const l2Version = versionMatch[1]; | ||
callback(l2Version); | ||
} | ||
}); | ||
} | ||
|
||
function compareL2Versions(currentVersion: string, latestVersion: string) { | ||
const curVersionParts = currentVersion.split("."); | ||
const lstVersionParts = latestVersion.split("."); | ||
for (let i = 0; i < 3; i++) { | ||
const curNum = Number(curVersionParts[i]); | ||
const lstNum = Number(lstVersionParts[i]); | ||
if (curNum > lstNum) { | ||
return 1; | ||
} | ||
if (lstNum > curNum) { | ||
return -1; | ||
} | ||
if (!isNaN(curNum) && isNaN(lstNum)) { | ||
return 1; | ||
} | ||
if (isNaN(curNum) && !isNaN(lstNum)) { | ||
return -1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
function showUpdateWarning() { | ||
function showUpdateWarning(minVersionToCheck: string) { | ||
const updateAction: vscode.MessageItem = { title: "Update" }; | ||
vscode.window | ||
.showWarningMessage( | ||
`Your Lama2 version is outdated. \nPlease update to version ${MIN_VERSION_TO_CHECK} or above for the best experience.\nUpdate: ${UPDATE_MSG}`, | ||
`Your Lama2 version is outdated. \nPlease update to version ${minVersionToCheck} or above for the best experience.\nUpdate: ${UPDATE_MSG}`, | ||
updateAction | ||
) | ||
.then((selectedAction) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which function call within this requires
async
? I don't see anyawait
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this, it wasn't needed