diff --git a/package.json b/package.json index db25993c..6e6c6fb0 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,8 @@ ".git", "env", "venv" - ] + ], + "description": "Files to be ignored by Pymakr." }, "pymakr.advancedMode": { "type": "boolean", @@ -135,9 +136,15 @@ "type": "string" }, "default": [ - ".*" + "manufacturer=Pycom", + "manufacturer=Pycom Ltd.", + "manufacturer=FTDI", + "manufacturer=Microsoft", + "manufacturer=Microchip Technology, Inc.", + "manufacturer=1a86" ], - "description": "Filter devices to include in the devices list. Uses regular expression. Will not include devices that match the exclude list." + + "description": "Filter devices to include in the devices list. Uses regular expression. Matches can be done against any property, eg. \"Microsoft\" or against a specific property, eg. \"manufacturer=Microsoft\r\n\r\nFor a list of available devices, run the command \"list devices\"." }, "pymakr.devices.exclude": { "type": "array", @@ -145,7 +152,7 @@ "type": "string" }, "default": [], - "description": "Filter devices to exclude from the devices list. Uses regular expression. Takes precedence over includes." + "description": "Same as Devices: Include, but for exclude. Excluded devices will not show, even if listed in the include list." } } }, @@ -208,6 +215,10 @@ ] }, "commands": [ + { + "command": "pymakr.listDevices", + "title": "List devices" + }, { "command": "pymakr.resetDevice", "title": "Hard reset device" diff --git a/src/PyMakr.js b/src/PyMakr.js index 8c9b2ca8..35ba3e33 100644 --- a/src/PyMakr.js +++ b/src/PyMakr.js @@ -13,6 +13,7 @@ const { writable } = require("./utils/store"); const { coerceDisposable } = require("./utils/misc"); const manifest = require("../package.json"); const { createVSCodeHelpers } = require("./utils/vscodeHelpers"); +const { TextDocumentProvider } = require("./providers/TextDocumentProvider"); /** * Pymakr is the root class and scope of the extension. @@ -58,6 +59,8 @@ class PyMakr { /** Provides device access for the file explorer */ this.fileSystemProvider = new FileSystemProvider(this); + this.textDocumentProvider = new TextDocumentProvider(this) + this.registerWithIde(); this.setup(); } @@ -74,6 +77,7 @@ class PyMakr { vscode.workspace.registerFileSystemProvider("telnet", this.fileSystemProvider, { isCaseSensitive: true }), vscode.window.registerTreeDataProvider("pymakr-projects-tree", this.projectsProvider), vscode.window.registerTreeDataProvider("pymakr-devices-tree", this.devicesProvider), + vscode.workspace.registerTextDocumentContentProvider("pymakrDocument", this.textDocumentProvider), vscode.workspace.onDidChangeConfiguration(this.onUpdatedConfig.bind(this)), vscode.window.registerTerminalProfileProvider("pymakr.terminal-profile", { provideTerminalProfile: () => ({ @@ -98,7 +102,7 @@ class PyMakr { /** * Registers usb devices and scans for projects in workspace */ - async setup() { + async setup() { await Promise.all([this.devicesStore.registerUSBDevices(), this.registerProjects()]); await this.recoverProjects(); this.projectsProvider.refresh(); // tell the provider that projects were updated diff --git a/src/commands/index.js b/src/commands/index.js index b8fb117a..165e810f 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -2,7 +2,7 @@ const { mkdirSync, readFileSync, writeFileSync } = require("fs"); const { writeFile } = require("fs").promises; const vscode = require("vscode"); const { msgs } = require("../utils/msgs"); -const { mapEnumsToQuickPick, getRelativeFromNearestParent } = require("../utils/misc"); +const { mapEnumsToQuickPick } = require("../utils/misc"); const { relative } = require("path"); /** @@ -43,6 +43,12 @@ class Commands { } commands = { + // todo link to this command from configuration's "Devices: Include" section + listDevices: async () => { + let uri = vscode.Uri.parse("pymakrDocument:" + "Pymakr: available devices"); + let doc = await vscode.workspace.openTextDocument(uri); // calls back into the provider + await vscode.window.showTextDocument(doc, { preview: false }); + }, /** * Reboot device * @param {DeviceTreeItem} treeItem @@ -320,7 +326,7 @@ class Commands { device.disconnect(); }, /** - * Creates a new terminal. If a terminal already exists for the given device, prompt + * Creates a new terminal. If a terminal already exists for the given device, prompt * the user if they want to to open a new shared terminal or the existing terminal * @param {ProjectDeviceTreeItem} treeItem */ diff --git a/src/providers/TextDocumentProvider.js b/src/providers/TextDocumentProvider.js new file mode 100644 index 00000000..3ef03470 --- /dev/null +++ b/src/providers/TextDocumentProvider.js @@ -0,0 +1,32 @@ +const { SerialPort } = require("serialport"); +const vscode = require("vscode"); +const { serializeKeyValuePairs } = require("../utils/misc"); + +/** + * @implements {vscode.TextDocumentContentProvider} + */ +class TextDocumentProvider { + /** + * @param {PyMakr} pymakr + */ + constructor(pymakr) { + this.pymakr = pymakr; + } + + provideTextDocumentContent(uri) { + const doc = this.paths[uri.path]; + if(typeof doc === 'undefined') throw new Error('could not find pymakr document: ' + uri.toString()) + return doc() + } + + paths = { + 'Pymakr: available devices': async () => { + const devices = await SerialPort.list(); + const devicesStr = devices.map((e) => serializeKeyValuePairs(e)).join("\r\n\r\n"); + + return devicesStr; + }, + }; +} + +module.exports = { TextDocumentProvider };