Skip to content
Open
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
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@
},
"dependencies": {
"fs-plus": "~3.1.1",
"platformio-node-helpers": "~11.3.0",
"platformio-node-helpers": "file:../platformio-node-helpers/platformio-node-helpers-11.3.0.tgz",
"platformio-vscode-debug": "~1.4.1"
},
"devDependencies": {
Expand All @@ -903,8 +903,5 @@
"prettier": "~3.4.2",
"webpack": "~5.97.1",
"webpack-cli": "~6.0.1"
},
"extensionDependencies": [
"ms-vscode.cpptools"
]
}
}
4 changes: 3 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export const IS_OSX = process.platform == 'darwin';
export const IS_LINUX = !IS_WINDOWS && !IS_OSX;
export const PIO_CORE_VERSION_SPEC = '>=6.1.6';
export const STATUS_BAR_PRIORITY_START = 10;
export const CPPTOOLS_EXTENSION_ID = 'ms-vscode.cpptools';
export const CLANGD_EXTENSION_ID = 'llvm-vs-code-extensions.vscode-clangd';

export const CONFLICTED_EXTENSION_IDS = [
'llvm-vs-code-extensions.vscode-clangd',
'vsciot-vscode.vscode-arduino',
'vscode-openapi',
];
8 changes: 4 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class PlatformIOVSCodeExtension {

async activate(context) {
this.context = context;
utils.setExtensionContext(context);
this.pioHome = new PIOHome();
this.pioTerm = new PIOTerminal();
this.subscriptions.push(this.pioHome, this.pioTerm, new PIOReleaseNotes());
Expand Down Expand Up @@ -100,6 +101,7 @@ class PlatformIOVSCodeExtension {

misc.maybeRateExtension();
misc.warnAboutConflictedExtensions();
misc.warnMissingIntelliSenseEngine();
this.subscriptions.push(
vscode.window.onDidChangeActiveTextEditor((editor) =>
misc.warnAboutInoFile(editor),
Expand All @@ -112,11 +114,9 @@ class PlatformIOVSCodeExtension {
}

loadEnterpriseSettings() {
const myId = this.context.extension.id;
const ext = vscode.extensions.all.find(
(item) =>
item.id.startsWith('platformio.') &&
item.id !== 'platformio.platformio-ide' &&
item.isActive,
(item) => item.id.startsWith('platformio.') && item.id !== myId && item.isActive,
);
return ext && ext.exports ? ext.exports.settings : undefined;
}
Expand Down
46 changes: 45 additions & 1 deletion src/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
* the root directory of this source tree.
*/

import { CONFLICTED_EXTENSION_IDS } from './constants';
import {
CLANGD_EXTENSION_ID,
CONFLICTED_EXTENSION_IDS,
CPPTOOLS_EXTENSION_ID,
} from './constants';
import { extension } from './main';
import vscode from 'vscode';

Expand Down Expand Up @@ -122,3 +126,43 @@ export async function warnAboutInoFile(editor) {
break;
}
}

export async function warnMissingIntelliSenseEngine() {
const hasCppTools = vscode.extensions.getExtension(CPPTOOLS_EXTENSION_ID);
const hasClangd = vscode.extensions.getExtension(CLANGD_EXTENSION_ID);

if (hasCppTools || hasClangd) {
return;
}

const stateKey = 'intellisense-warn-disabled';
if (extension.context.globalState.get(stateKey)) {
return;
}

const selectedItem = await vscode.window.showWarningMessage(
'PlatformIO recommends installing a C/C++ Language Server (like Microsoft C/C++ or Clangd) for full IntelliSense.',
{ title: 'Install Microsoft C/C++', isCloseAffordance: false },
{ title: 'Install Clangd', isCloseAffordance: false },
{ title: 'Do not show again', isCloseAffordance: false },
{ title: 'Remind later', isCloseAffordance: true },
);

switch (selectedItem ? selectedItem.title : undefined) {
case 'Install Microsoft C/C++':
vscode.commands.executeCommand(
'workbench.extensions.installExtension',
CPPTOOLS_EXTENSION_ID,
);
break;
case 'Install Clangd':
vscode.commands.executeCommand(
'workbench.extensions.installExtension',
CLANGD_EXTENSION_ID,
);
break;
case 'Do not show again':
extension.context.globalState.update(stateKey, 1);
break;
}
}
14 changes: 13 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,20 @@ export async function notifyError(title, err) {
console.error(err);
}

let _extensionContext = null;

export function setExtensionContext(context) {
_extensionContext = context;
}

export function getIDEManifest() {
return vscode.extensions.getExtension('platformio.platformio-ide').packageJSON;
if (!_extensionContext) {
console.warn(
'Attempting to get IDE manifest before extension context was injected.',
);
return { version: '0.0.0' }; // safe fallback
}
return _extensionContext.extension.packageJSON;
}

export function getIDEVersion() {
Expand Down