-
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
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { exec } from "child_process"; | ||
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() { | ||
try { | ||
getL2Version((l2Version) => { | ||
// Check if version is below MIN_VERSION_TO_CHECK | ||
if (compareL2Versions(l2Version, MIN_VERSION_TO_CHECK) < 0) { | ||
showUpdateWarning(); | ||
} | ||
}); | ||
} catch (e: any) { | ||
console.log("Problem while checking for version -> ", e); | ||
} | ||
} | ||
|
||
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) { | ||
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. Why 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. 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. Damn never knew so many kinds are there |
||
const l2Version = versionMatch[1]; | ||
callback(l2Version); | ||
} | ||
}); | ||
} | ||
|
||
function compareL2Versions(currentVersion: string, latestVersion: string) { | ||
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. I recommend using a library suggested in this SO Answer. Our semver definition is simple now, but there are more changes possible. Best to simply use standardized library for it. Should be as simple as:
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. If we're using this library, then ignore the previous comment about regex*. 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 using this |
||
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() { | ||
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}`, | ||
updateAction | ||
) | ||
.then((selectedAction) => { | ||
if (selectedAction === updateAction) { | ||
runL2UpdateCommand(); | ||
} | ||
}); | ||
} | ||
|
||
function runL2UpdateCommand() { | ||
const terminal: any = getShowLama2Term(LAMA2_TERM_NAME); | ||
terminal.sendText("l2 -u"); | ||
terminal.show(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import { replaceTextAfterEnvSelected, suggestENVs } from "./suggestEnvironmentVa | |
import { genLama2Examples } from "./genLama2Examples"; | ||
import { execCurL2File } from "./executeCurrentFile"; | ||
import { prettifyL2File } from "./prettifyL2File"; | ||
import { checkL2Version } from "./checkL2Version"; | ||
|
||
export function activate(context: vscode.ExtensionContext) { | ||
console.log('>>> Congratulations, your extension "Lama2" is now active!'); | ||
|
@@ -34,6 +35,9 @@ export function activate(context: vscode.ExtensionContext) { | |
context.subscriptions.push(generateCodeSnippetDisposable); | ||
console.log(">>> generateCodeSnippetDisposable is now active!"); | ||
|
||
// Automatically check L2 version on extension activation | ||
checkL2Version(); | ||
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. So if version is too old, what happens to the variable suggestion? Is it totally dead in older versions? 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. No in the older version what we were doing is searching the le.env file in front end and suggesting it. So it won't be a problem. 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. What I am saying is something else. Say, the extension frontend updates, but the l2 version is still old, what happens? Remember - VSCode automatically updates extensions quite quickly (I think) |
||
|
||
let suggestEnvVariables = suggestENVs(); | ||
context.subscriptions.push( | ||
suggestEnvVariables, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as vscode from "vscode"; | ||
|
||
// Define a custom interface for the terminal object (optional, based on your specific use case) | ||
interface CustomTerminal extends vscode.Terminal { | ||
name: string; | ||
} | ||
|
||
function getActiveTerminals(): CustomTerminal[] { | ||
// Convert the readonly array to a mutable array by creating a copy | ||
return vscode.window.terminals.slice(); | ||
} | ||
|
||
function findTerminalsByName(name: string): CustomTerminal | undefined { | ||
let terminals = getActiveTerminals(); | ||
let found = terminals.find((element) => element.name === name); | ||
return found; | ||
} | ||
|
||
function findOrCreateTerminal(name: string): CustomTerminal { | ||
let terminal = findTerminalsByName(name); | ||
if (!terminal) { | ||
terminal = vscode.window.createTerminal(name); | ||
} | ||
return terminal; | ||
} | ||
|
||
export function getShowLama2Term(name: string): CustomTerminal { | ||
let terminal = findOrCreateTerminal(name); | ||
// Clear terminal and send Ctrl+C before showing | ||
terminal.sendText("\x03"); | ||
terminal.show(); | ||
return terminal; | ||
} |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah added