Skip to content

Commit

Permalink
Merge pull request #7 from DanielHuey/bugfix/recursive-call-in-util.js
Browse files Browse the repository at this point in the history
Bugfix where extension won't start
  • Loading branch information
DanielHuey authored Nov 1, 2024
2 parents 957a905 + 098e08a commit 975c6e1
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ jobs:
- name: Save artifact
uses: actions/upload-artifact@v3
with:
name: extension-latest.vsix
name: extension-latest
path: "*.vsix"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the "avr-utils" extension will be documented in this file.

### [0.1.5]
- The previous error had persisted but i have fixed it this time for good!
- A certain function was making the extension fail to start, but it has been fixed too.

### [0.1.4]
- Fix error where commands like "Create New Project" in the command palette claim that they are missing ( Would happen especially on VSCode version < 1.75 ).
- Added a progress bar when downloading the toolchain, so that you (the user) are aware of the process.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ Welcome to **`avr-utils`**.

This extension helps users to write and compile code for their avr microcontrollers straight from the comfort of their favourite Code editor, **VScode**

## !! New !!
```yml
New Features:
- Progress bar when downloading toolchain.
- Better error message diagnostics (Big Improvement!)
- Simplified Commenting of code.
```
More in [Changelog.md](./CHANGELOG.md)
Expand Down
10 changes: 7 additions & 3 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ const { dataObject } = require("./src/utils");
/**
* @param {vscode.ExtensionContext} context
*/
async function activate(context) {
function activate(context) {
console.log("Checking for data.json")
dataObject(); // To initialize the data.json file
console.log("Registering commands")
registerCommands();
// DO NOT MOVE THESE LINES ABOVE. THESE 2 LINES MUST BE FIRST
await init(context);
// DO NOT MOVE THESE LINES ABOVE. THEY MUST COME FIRST
console.log("Initializing other dependencies")
init(context);

console.log("Registering providers")
registerProviders(context);

console.log('"avr-utils" is now active!');
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "avr-utils",
"displayName": "AVR Utils",
"description": "This extension will help you to compile code for avr based microcontrollers straight from the comfort of your favourite code editor!",
"version": "0.1.4",
"version": "0.1.5",
"repository": {
"url": "https://github.com/DanielHuey/avr-utils.git",
"type": "git"
Expand All @@ -18,7 +18,6 @@
"activationEvents": [
"onLanguage:avr-c",
"onLanguage:asm",
"onStartupFinished",
"onCommand:avr-utils.makeProject",
"onCommand:avr-utils.openMicrochipStudioProject"
],
Expand Down
1 change: 0 additions & 1 deletion src/commands/compileProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const {
toolchainDir,
dataObject,
currentExtension,
sendCursorTo,
} = require("../utils");
const { resetIncludeDir } = require("../providers/documentLinkProvider");
const { generateDiagnostics, clearDiagnostics } = require("../providers/diagnosticsProvider")
Expand Down
33 changes: 7 additions & 26 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ const selectDeviceButton = vscode.window.createStatusBarItem(vscode.StatusBarAli
*
* @param {vscode.ExtensionContext} context
*/
async function init(context) {
function init(context) {
vscode.commands.registerCommand("avr-utils.selectDevice", selectDevice);

getWorkspaceRelatedStuff(context);
setupWorkspaceProperties(context);
vscode.workspace.onDidChangeWorkspaceFolders((event) => {
if (event.removed.length > 0) {
workspaceNotYetAccessible = true;
context.subscriptions.pop();
context.subscriptions.pop();
if (vscode.workspace.workspaceFolders) getWorkspaceRelatedStuff(context);
if (vscode.workspace.workspaceFolders) setupWorkspaceProperties(context);
}
if (event.added.length > 0) {
getWorkspaceRelatedStuff(context);
setupWorkspaceProperties(context);
}
});

Expand All @@ -37,7 +37,6 @@ async function init(context) {
});

initButtons();
buttonVisibility();
}

/**
Expand All @@ -46,8 +45,10 @@ async function init(context) {
function showOrHideUI(editor) {
if (editor && (editor.document.languageId === 'avr-c' || editor.document.languageId === 'asm')) {
vscode.commands.executeCommand('setContext', 'avr-utils.isAvrC', true);
toggleButtons();
} else {
vscode.commands.executeCommand('setContext', 'avr-utils.isAvrC', false);
toggleButtons(true);
}
}

Expand All @@ -68,26 +69,6 @@ function initButtons() {
selectDeviceButton.command = "avr-utils.selectDevice";
}

async function buttonVisibility() {
while (true) {
await new Promise((r) => {
setTimeout(r, 500);
});
try {
if (vscode.window.activeTextEditor) {
if (vscode.window.activeTextEditor.document.languageId !== "avr-c" && vscode.window.activeTextEditor.document.languageId !== "asm") {
toggleButtons(true);
} else {
toggleButtons();
}
} else {
toggleButtons(true);
}
} finally {
}
}
}

function toggleButtons(hide = false) {
if (hide) {
if (_compileButtonVisible) compileButton.hide();
Expand Down Expand Up @@ -140,7 +121,7 @@ let workspaceNotYetAccessible = true;
/**
* @param {vscode.ExtensionContext} context
*/
async function getWorkspaceRelatedStuff(context) {
async function setupWorkspaceProperties(context) {
if (workspaceNotYetAccessible) {
if (vscode.workspace.workspaceFolders) {
initWorkspace(); // enables the "workspace" utils
Expand Down
1 change: 1 addition & 0 deletions src/providers/diagnosticsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ function clearDiagnostics() {
module.exports = {
generateDiagnostics,
clearDiagnostics,
diagnosticsCollection: globalDiagnostics,
}
3 changes: 2 additions & 1 deletion src/registerProviders.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const { defaultCompletions } = require("./providers/completionsProvider");
const { includeDirProvider } = require("./providers/documentLinkProvider");
const { definitions } = require("./providers/definitionProvider");
const { diagnosticsCollection } = require("./providers/diagnosticsProvider");

/**@param {import("vscode").ExtensionContext} context */
function _(context) {
context.subscriptions.push(defaultCompletions, includeDirProvider, definitions);
context.subscriptions.push(defaultCompletions, includeDirProvider, definitions, diagnosticsCollection);
}

module.exports = _;
11 changes: 8 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,19 @@ async function changeWorkspace() {
* @param {Object} saveObject
*/
function dataObject(saveObject = null) {
const pathToDataFile = path.join(__dirname, "storage", "data.json");
if (saveObject) {
const oldObject = dataObject();
let oldObject = {};
try {
fs.statSync(pathToDataFile);
oldObject = dataObject();
} catch {}
let newObject = {...oldObject, ...saveObject};
fs.writeFileSync(path.join(__dirname, "storage", "data.json"), JSON.stringify(newObject), "utf-8");
fs.writeFileSync(pathToDataFile, JSON.stringify(newObject), "utf-8");
return;
}
try {
return JSON.parse(fs.readFileSync(path.join(__dirname, "storage", "data.json"), "utf8"));
return JSON.parse(fs.readFileSync(pathToDataFile, "utf8"));
} catch {
let temp = {toolchain_directory: `${path.join(homedir(), "Documents")}`};
dataObject(temp);
Expand Down

0 comments on commit 975c6e1

Please sign in to comment.