Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
- Generate Python Wrapper from a TSP Script.
- **tsp-toolkit-trigger-flow** - Status banner to show information, warnings and errors that do not belong to a specific model.
- TSP language interop feature.
- Added method to fetch the Keithley examples repository
- Continuously discover instruments by default (disable by setting the `tsp.autorefresh` setting to `false`)
- **tsp-toolkit-language-interop** - Implement tsp language interop feature
- Added configurable 'Connection Timeout' as a VS Code setting for instrument connections.
Expand Down
20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,14 @@
"title": "Generate Python Wrapper from a TSP Script",
"category": "TSP",
"icon": "$(python)"
},
{
"command": "tsp.fetchExampleScripts",
"title": "Import TSP Example Scripts",
"category": "TSP"

}

],
"configuration": {
"type": "object",
Expand Down Expand Up @@ -513,12 +520,16 @@
{
"when": "activeEditor && ( resourceExtname == .tsp || resourceExtname == .tspa )",
"command": "tsp.sendFile",
"group": "navigation"
"group": "tsp"
},
{
"when": "resourceExtname == .tsp",
"command": "tsp.convertToPython",
"group": "navigation"
"group": "tsp"
},
{
"command": "tsp.fetchExampleScripts",
"group": "tsp"
}
],
"editor/title/context": [
Expand Down Expand Up @@ -728,6 +739,11 @@
"id": "ToolsView",
"name": "Tools",
"icon": "resources/dark/script-gen-pane-icon.svg"
},
{
"id": "extraActions",
"name": "Extra Actions",
"type": "webview"
}
]
},
Expand Down
101 changes: 101 additions & 0 deletions src/ExtraActionsWebView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import * as vscode from "vscode"
import { Uri, Webview, WebviewView, WebviewViewProvider } from "vscode"

export class ExtraActionsWebView implements WebviewViewProvider {
public static readonly viewType = "extraActions"
private _webviewView: vscode.WebviewView | undefined
constructor(private readonly _extensionUri: Uri) {}

resolveWebviewView(
webviewView: vscode.WebviewView,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_context: vscode.WebviewViewResolveContext,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_token: vscode.CancellationToken,
) {
this._webviewView = webviewView
// Allow scripts in the webview
webviewView.webview.options = {
// Enable JavaScript in the webview
enableScripts: true,
// Restrict the webview to only load resources from the `out` directory
localResourceRoots: [Uri.joinPath(this._extensionUri)],
}

// Set the HTML content that will fill the webview view
webviewView.webview.html = this._getWebviewContent(webviewView.webview)

// Sets up an event listener to listen for messages passed from the webview view context
// and executes code based on the message that is recieved
this._setWebviewMessageListener(webviewView)
}
private _getWebviewContent(webview: Webview) {
const webviewScriptUri = this.getUri(webview, this._extensionUri, [
"out",
"extraActions.js",
])
const stylesUri = this.getUri(webview, this._extensionUri, [
"out",
"styles.css",
])
const codiconsUri = this.getUri(webview, this._extensionUri, [
"node_modules",
"@vscode/codicons",
"dist",
"codicon.css",
])
const nonce = this.getNonce()
return /*html*/ `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy"
content="default-src 'none'; style-src ${webview.cspSource}; script-src 'nonce-${nonce}'; font-src ${webview.cspSource};">
<link rel="stylesheet" href="${stylesUri.toString()}">
<link rel="stylesheet" href="${codiconsUri.toString()}">
<title>Extra Actions</title>
</head>

<body>
<div id="action-container"></div>
<script type="module" nonce="${nonce}" src="${webviewScriptUri.toString()}"></script>
<button class="vscode-style-button" data-id="fetchExamples" id="fetchExamples" type="button">Import TSP Examples</button>
</div>
</body>
</html>
`
}

private _setWebviewMessageListener(webviewView: WebviewView) {
webviewView.webview.onDidReceiveMessage(async (message) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
switch (message.command) {
case "fetchExamples": {
await vscode.commands.executeCommand(
"tsp.fetchExampleScripts",
)
this._webviewView?.webview.postMessage({
command: "fetchComplete",
})
Comment thread
suribabu-ganti marked this conversation as resolved.
break
}
}
})
}

private getNonce() {
let text = ""
const possible =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
for (let i = 0; i < 32; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length))
}
return text
}

private getUri(webview: Webview, extensionUri: Uri, pathList: string[]) {
return webview.asWebviewUri(Uri.joinPath(extensionUri, ...pathList))
}
}
3 changes: 0 additions & 3 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ export class Connection extends vscode.TreeItem implements vscode.Disposable {

if (this._status !== status) {
this._status = status
console.error(`[${this._addr}]: status = ${status}`)
this._onChangedStatus.fire(this._status)
}
}
Expand All @@ -220,7 +219,6 @@ export class Connection extends vscode.TreeItem implements vscode.Disposable {
}

set foundLastRound(a: boolean) {
console.error(`[${this.addr}: foundLastRound = ${a}]`)
this._foundLastRound = a
}
get foundLastRound(): boolean {
Expand Down Expand Up @@ -1587,7 +1585,6 @@ export class Connection extends vscode.TreeItem implements vscode.Disposable {
}

if (this.status !== new_status) {
console.error("getUpdatedStatus: Updating status")
this.status = new_status
this.foundLastRound = true
this._onChangedStatus.fire(this.status)
Expand Down
83 changes: 78 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from "vscode"

import { ProgressLocation } from "vscode"
import { EXECUTABLE } from "./kic-cli"
import { Instrument } from "./instrument"
import { HelpDocumentWebView } from "./helpDocumentWebView"
Expand All @@ -23,7 +24,7 @@ import { TriggerFlowDataProvider } from "./triggerFlowDataProvider"
import { CombinedScriptGenDataProvider } from "./combinedScriptGenDataProvider"
import { TriggerFlowWebViewManager } from "./triggerFlowWebViewManager"
import { GenericSessionStorage } from "./genericSessionStorage"
import { isMacOS } from "./utility"
import { extractTarGzToDisk, isMacOS } from "./utility"
import { convertTspToPython } from "./tspConverter"
import {
checkSystemDependencies,
Expand All @@ -32,6 +33,7 @@ import {
isLinux,
isWindows,
} from "./dependencyChecker"
import { ExtraActionsWebView } from "./ExtraActionsWebView"

let _instrExplorer: InstrumentsExplorer
let _tspConverterDiagnostics: vscode.DiagnosticCollection
Expand Down Expand Up @@ -155,11 +157,16 @@ export async function createTerminal(
)

const existing =
InstrumentProvider.instance.getConnection(connection_details)
InstrumentProvider.instance.getConnection(
connection_details,
)

conn =
existing ??
new Connection(connection_details.type, connection_details.addr)
new Connection(
connection_details.type,
connection_details.addr,
)
name = connection_details.name
} else {
conn = connection
Expand Down Expand Up @@ -562,6 +569,61 @@ export async function activate(context: vscode.ExtensionContext) {
await convertTspToPython(e, _tspConverterDiagnostics)
},
},
{
name: "tsp.fetchExampleScripts",
cb: async (uri: vscode.Uri | undefined) => {
await vscode.window.withProgress(
{
location: ProgressLocation.Notification,
},
async (progress) => {
progress.report({ message: "Fetching script examples" })
if (!uri) {
const user_uri = await vscode.window.showOpenDialog(
{
title: "Select Folder to Save Example Scripts",
openLabel: "Save",
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
},
)
if (user_uri) {
// The user can only select 1 based on the options above
uri = user_uri[0]
} else {
return
}
}

try {
const resp = await fetch(
"https://github.com/tektronix/keithley/archive/refs/heads/main.tar.gz",
{
method: "GET",
mode: "cors",
},
)
if (!resp.ok) {
vscode.window.showErrorMessage(
`Unable to get the example scripts: ${resp.statusText}`,
)
return
Comment thread
suribabu-ganti marked this conversation as resolved.
}
const buffer = await resp.arrayBuffer()
progress.report({
message: `Extracting example scripts to ${uri.fsPath}`,
})
await extractTarGzToDisk(buffer, uri.fsPath)
} catch (e) {
vscode.window.showErrorMessage(
`Unable to get the example scripts: ${e instanceof Error ? e.message : String(e)}`,
)
}
},
)
},
},
])

Log.debug("Setting up HelpDocumentWebView", LOGLOC)
Expand All @@ -584,6 +646,17 @@ export async function activate(context: vscode.ExtensionContext) {

context.subscriptions.push(systemConfigViewDisposable)

const extraActionsWebViewProvider = new ExtraActionsWebView(
context.extensionUri,
)
const extraActionsViewDisposable =
vscode.window.registerWebviewViewProvider(
ExtraActionsWebView.viewType,
extraActionsWebViewProvider,
)

context.subscriptions.push(extraActionsViewDisposable)

Log.debug(
"Checking to see if workspace folder contains `*.tsp` files",
LOGLOC,
Expand Down Expand Up @@ -1049,7 +1122,7 @@ async function resetToolkitDefaults() {
// await vscode.window.showInformationMessage("Nothing to reset.")
// return
// }

const resetSummary = previewResults
.map((result, index) => {
const warningLine = result.preview.warningNote
Expand All @@ -1075,7 +1148,7 @@ async function resetToolkitDefaults() {
for (const result of executableItems) {
await result.item.action.execute()
}

vscode.window.showInformationMessage("Reset completed successfully.")
}

Expand Down
36 changes: 36 additions & 0 deletions src/extraActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Get access to the VS Code API from within the webview context
const vscode = acquireVsCodeApi();

window.addEventListener("load", main)

// Set up an event listener to listen for messages passed from the extension context
async function waitForEventWith(predicate) {
return new Promise((res, rej) => {
const event_listener = (event) => {
if (predicate(event.data)) {
window.removeEventListener("message", event_listener)
res()

}
}
window.addEventListener("message", event_listener);
})
}

async function fetchExamples() {
return new Promise(async (resolve, reject) => {
vscode.postMessage({command: "fetchExamples"})
await waitForEventWith((data) => {return data.command === "fetchComplete"})
resolve()
})
}

async function main() {
const fetchExamplesButton = document.getElementById("fetchExamples")

fetchExamplesButton.addEventListener("click", async (event) => {
fetchExamplesButton.disabled = true
await fetchExamples()
fetchExamplesButton.disabled = false
})
}
20 changes: 13 additions & 7 deletions src/genericSessionStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,22 @@ export class GenericSessionStorage {
// either migrated in this run, or already present in the new keys, or
// there were no sessions to migrate for that type.
const scriptGenAccountedFor =
migratedScriptGen || scriptGenHasSessions || ivSessions.length === 0
migratedScriptGen ||
scriptGenHasSessions ||
ivSessions.length === 0
const triggerFlowAccountedFor =
migratedTriggerFlow || triggerFlowHasSessions || triggerFlowSessions.length === 0
migratedTriggerFlow ||
triggerFlowHasSessions ||
triggerFlowSessions.length === 0

if (scriptGenAccountedFor && triggerFlowAccountedFor) {
await vscode.workspace.getConfiguration("tsp").update(
GenericSessionStorage.LEGACY_SETTINGS_KEY,
undefined,
false,
)
await vscode.workspace
.getConfiguration("tsp")
.update(
GenericSessionStorage.LEGACY_SETTINGS_KEY,
undefined,
false,
)
}
} catch (error) {
console.error("Failed to migrate legacy sessions:", error)
Expand Down
Loading
Loading