Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Adds a ts api for third party extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
nosknut committed Jul 13, 2023
1 parent 9544a5f commit 578a78e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ export class ArduinoApp {
if (this._settings.analyzeOnSettingChange) {
// set up event handling for IntelliSense analysis
const requestAnalysis = async () => {
if (isCompilerParserEnabled()) {
await this._analysisManager.requestAnalysis();
// Check again in case the setting was disabled after initialization
if (this._settings.analyzeOnSettingChange) {
if (isCompilerParserEnabled()) {
await this._analysisManager.requestAnalysis();
}
}
};
const dc = DeviceContext.getInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/arduino/boardManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export class BoardManager {
}
}

private listBoards(): IBoard[] {
public listBoards(): IBoard[] {
const result = [];
this._boards.forEach((b) => {
result.push(b);
Expand Down
4 changes: 2 additions & 2 deletions src/arduino/programmerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ProgrammerManager {
DeviceContext.getInstance().programmer = this._programmerValue;
}

private setProgrammerValue(programmerName: string | null) {
public setProgrammerValue(programmerName: string | null) {
const programmer = this._arduinoApp.boardManager.installedProgrammers.get(programmerName);
this._programmerValue = this._settings.useArduinoCli ? programmerName : programmer ? programmer.key : programmerName;
this._programmerDisplayName = this._programmerValue
Expand All @@ -71,7 +71,7 @@ export class ProgrammerManager {
return programmer ? programmer.displayName : programmerName;
}

private getAvailableProgrammers(currentBoard: IBoard): IProgrammer[] {
public getAvailableProgrammers(currentBoard: IBoard): IProgrammer[] {
if (!currentBoard || !currentBoard.platform) {
return [];
}
Expand Down
49 changes: 48 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as vscode from "vscode";
import * as constants from "./common/constants";
const arduinoContentProviderModule =
impor("./arduino/arduinoContentProvider") as typeof import ("./arduino/arduinoContentProvider");
import { IBoard } from "./arduino/package";
import { IBoard, IProgrammer } from "./arduino/package";
import { VscodeSettings } from "./arduino/vscodeSettings";
const arduinoActivatorModule = impor("./arduinoActivator") as typeof import ("./arduinoActivator");
const arduinoContextModule = impor("./arduinoContext") as typeof import ("./arduinoContext");
Expand All @@ -26,6 +26,7 @@ const completionProviderModule = impor("./langService/completionProvider") as ty
import { BuildMode } from "./arduino/arduino";
import * as Logger from "./logger/logger";
import { SerialMonitor } from "./serialmonitor/serialMonitor";
import { ArduinoContentProvider } from "./arduino/arduinoContentProvider";
const usbDetectorModule = impor("./serialmonitor/usbDetector") as typeof import ("./serialmonitor/usbDetector");

export async function activate(context: vscode.ExtensionContext) {
Expand Down Expand Up @@ -383,10 +384,17 @@ export async function activate(context: vscode.ExtensionContext) {
}
Logger.traceUserData("end-activate-extension", { correlationId: activeGuid });

// Makes the provider available to the programmatic api
const provider: {
arduinoManagerProvider?: ArduinoContentProvider,
} = {};

setTimeout(async () => {
const arduinoManagerProvider = new arduinoContentProviderModule.ArduinoContentProvider(context.extensionPath);
await arduinoManagerProvider.initialize();

provider.arduinoManagerProvider = arduinoManagerProvider;

context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider(ARDUINO_MANAGER_PROTOCOL, arduinoManagerProvider));
registerArduinoCommand("arduino.showBoardManager", async () => {
const panel = vscode.window.createWebviewPanel("arduinoBoardManager", "Arduino Board Manager", vscode.ViewColumn.Two, {
Expand Down Expand Up @@ -447,6 +455,45 @@ export async function activate(context: vscode.ExtensionContext) {
usbDetectorModule.UsbDetector.getInstance().initialize(context);
usbDetectorModule.UsbDetector.getInstance().startListening();
}, 200);

return {
getCurrentBoard() {
return arduinoContextModule.default.boardManager.currentBoard;
},
getBoardTypes() {
return arduinoContextModule.default.boardManager.listBoards();
},
changeBoardType(board: IBoard) {
arduinoContextModule.default.boardManager.doChangeBoardType(board);
provider.arduinoManagerProvider.update(LIBRARY_MANAGER_URI);
provider.arduinoManagerProvider.update(EXAMPLES_URI);
return { board: arduinoContextModule.default.boardManager.currentBoard };
},
installBoard: async (packageName: string, arch: string = "", version: string = "", showOutput: boolean = true) => {
await arduinoContextModule.default.arduinoApp.installBoard(packageName, arch, version, showOutput)
},
getCurrentProgrammer() {
return DeviceContext.getInstance().programmer;
},
getAvailableProgrammers(board: IBoard) {
return arduinoContextModule.default.arduinoApp.programmerManager.getAvailableProgrammers(board)
},
selectProgrammer(programmer: IProgrammer) {
if (!arduinoContextModule.default.arduinoApp.building) {
try {
arduinoContextModule.default.arduinoApp.programmerManager.setProgrammerValue(programmer.name);
DeviceContext.getInstance().programmer = arduinoContextModule.default.arduinoApp.programmerManager.currentProgrammer;
return true;
} catch (ex) {
return false;
}
}
},
selectSketch(relativeSketchPath: string) {
deviceContext.sketch = relativeSketchPath;
deviceContext.showStatusBar();
},
}
}

export async function deactivate() {
Expand Down

0 comments on commit 578a78e

Please sign in to comment.