diff --git a/package.json b/package.json index dc36fab3..5869d3c8 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -903,8 +903,5 @@ "prettier": "~3.4.2", "webpack": "~5.97.1", "webpack-cli": "~6.0.1" - }, - "extensionDependencies": [ - "ms-vscode.cpptools" - ] + } } diff --git a/src/constants.js b/src/constants.js index 16d4b667..060e0e94 100644 --- a/src/constants.js +++ b/src/constants.js @@ -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', ]; diff --git a/src/main.js b/src/main.js index b3bac80c..d009e925 100644 --- a/src/main.js +++ b/src/main.js @@ -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()); @@ -100,6 +101,7 @@ class PlatformIOVSCodeExtension { misc.maybeRateExtension(); misc.warnAboutConflictedExtensions(); + misc.warnMissingIntelliSenseEngine(); this.subscriptions.push( vscode.window.onDidChangeActiveTextEditor((editor) => misc.warnAboutInoFile(editor), @@ -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; } diff --git a/src/misc.js b/src/misc.js index cb340885..cdcabd27 100644 --- a/src/misc.js +++ b/src/misc.js @@ -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'; @@ -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; + } +} diff --git a/src/utils.js b/src/utils.js index 31ea5264..e81d0039 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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() {