-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[VSC-1409] Add check for missing compile_commands.json in IDF projects #1271
base: master
Are you sure you want to change the base?
Changes from all commits
e4f0e6c
214caa1
d298bf6
c8f9ec8
0fa8e6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ import { | |
workspace, | ||
} from "vscode"; | ||
import { NotificationMode, readParameter } from "../../idfConfiguration"; | ||
import { appendIdfAndToolsToPath, compareVersion, getEspIdfFromCMake, getSDKConfigFilePath } from "../../utils"; | ||
import { appendIdfAndToolsToPath, getSDKConfigFilePath } from "../../utils"; | ||
import { join } from "path"; | ||
import { TaskManager } from "../../taskManager"; | ||
import { getVirtualEnvPythonPath } from "../../pythonManager"; | ||
|
@@ -65,18 +65,12 @@ export class IdfReconfigureTask { | |
|
||
const idfPy = join(this.idfPathDir, "tools", "idf.py"); | ||
const reconfigureArgs = [idfPy]; | ||
const espIdfVersion = await getEspIdfFromCMake(this.idfPathDir); | ||
const useEqualSign = compareVersion(espIdfVersion, "4.4") >= 0; | ||
|
||
let buildPathArgsIndex = reconfigureArgs.indexOf("-B"); | ||
if (buildPathArgsIndex !== -1) { | ||
reconfigureArgs.splice(buildPathArgsIndex, useEqualSign ? 1 : 2); | ||
} | ||
if (useEqualSign) { | ||
reconfigureArgs.push(`-B=${this.buildDirPath}`); | ||
} else { | ||
reconfigureArgs.push("-B", this.buildDirPath); | ||
reconfigureArgs.splice(buildPathArgsIndex, 2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here removing changes in master from #1266 |
||
} | ||
reconfigureArgs.push("-B", this.buildDirPath); | ||
|
||
const sdkconfigFile = await getSDKConfigFilePath(this.curWorkspace); | ||
if (reconfigureArgs.indexOf("SDKCONFIG") === -1) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ import { ExamplesPlanel } from "./examples/ExamplesPanel"; | |
import * as idfConf from "./idfConfiguration"; | ||
import { Logger } from "./logger/logger"; | ||
import { OutputChannel } from "./logger/outputChannel"; | ||
import { showInfoNotificationWithAction } from "./logger/utils"; | ||
import * as utils from "./utils"; | ||
import { PreCheck } from "./utils"; | ||
import { | ||
|
@@ -391,77 +392,81 @@ export async function activate(context: vscode.ExtensionContext) { | |
binTimestampEventFunc | ||
); | ||
context.subscriptions.push(buildWatcherCreateDisposable); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes from 394 to 469 are not related to the PR proposal solution. While I think is good to add this to Please update to remove these changes. |
||
vscode.workspace.onDidChangeWorkspaceFolders(async (e) => { | ||
if (PreCheck.isWorkspaceFolderOpen()) { | ||
for (const ws of e.removed) { | ||
if (workspaceRoot && ws.uri === workspaceRoot) { | ||
workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]); | ||
await getIdfTargetFromSdkconfig( | ||
workspaceRoot, | ||
statusBarItems["target"] | ||
); | ||
if (statusBarItems && statusBarItems["port"]) { | ||
statusBarItems["port"].text = | ||
`$(${commandDictionary[CommandKeys.SelectSerialPort].iconId}) ` + | ||
idfConf.readParameter("idf.port", workspaceRoot); | ||
} | ||
if (statusBarItems["projectConf"]) { | ||
statusBarItems["projectConf"].dispose(); | ||
statusBarItems["projectConf"] = undefined; | ||
const selectedConfig = ESP.ProjectConfiguration.store.get<string>( | ||
ESP.ProjectConfiguration.SELECTED_CONFIG | ||
context.subscriptions.push( | ||
vscode.workspace.onDidChangeWorkspaceFolders(async (e) => { | ||
if (PreCheck.isWorkspaceFolderOpen()) { | ||
for (const ws of e.removed) { | ||
if (workspaceRoot && ws.uri === workspaceRoot) { | ||
workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]); | ||
await getIdfTargetFromSdkconfig( | ||
workspaceRoot, | ||
statusBarItems["target"] | ||
); | ||
ESP.ProjectConfiguration.store.clear(selectedConfig); | ||
ESP.ProjectConfiguration.store.clear( | ||
ESP.ProjectConfiguration.SELECTED_CONFIG | ||
if (statusBarItems && statusBarItems["port"]) { | ||
statusBarItems["port"].text = | ||
`$(${ | ||
commandDictionary[CommandKeys.SelectSerialPort].iconId | ||
}) ` + idfConf.readParameter("idf.port", workspaceRoot); | ||
} | ||
if (statusBarItems["projectConf"]) { | ||
statusBarItems["projectConf"].dispose(); | ||
statusBarItems["projectConf"] = undefined; | ||
const selectedConfig = ESP.ProjectConfiguration.store.get<string>( | ||
ESP.ProjectConfiguration.SELECTED_CONFIG | ||
); | ||
ESP.ProjectConfiguration.store.clear(selectedConfig); | ||
ESP.ProjectConfiguration.store.clear( | ||
ESP.ProjectConfiguration.SELECTED_CONFIG | ||
); | ||
} | ||
const currentIdfSetup = await getCurrentIdfSetup( | ||
workspaceRoot, | ||
false | ||
); | ||
if (statusBarItems["currentIdfVersion"]) { | ||
statusBarItems["currentIdfVersion"].text = currentIdfSetup.isValid | ||
? `$(${ | ||
commandDictionary[CommandKeys.SelectCurrentIdfVersion] | ||
.iconId | ||
}) ESP-IDF v${currentIdfSetup.version}` | ||
: `$(${ | ||
commandDictionary[CommandKeys.SelectCurrentIdfVersion] | ||
.iconId | ||
}) ESP-IDF InvalidSetup`; | ||
} | ||
const coverageOptions = getCoverageOptions(workspaceRoot); | ||
covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions); | ||
break; | ||
} | ||
const currentIdfSetup = await getCurrentIdfSetup( | ||
} | ||
if (typeof workspaceRoot === undefined) { | ||
workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]); | ||
await getIdfTargetFromSdkconfig( | ||
workspaceRoot, | ||
false | ||
statusBarItems["target"] | ||
); | ||
if (statusBarItems["currentIdfVersion"]) { | ||
statusBarItems["currentIdfVersion"].text = currentIdfSetup.isValid | ||
? `$(${ | ||
commandDictionary[CommandKeys.SelectCurrentIdfVersion].iconId | ||
}) ESP-IDF v${currentIdfSetup.version}` | ||
: `$(${ | ||
commandDictionary[CommandKeys.SelectCurrentIdfVersion].iconId | ||
}) ESP-IDF InvalidSetup`; | ||
} | ||
const coverageOptions = getCoverageOptions(workspaceRoot); | ||
covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions); | ||
break; | ||
} | ||
const buildDirPath = idfConf.readParameter( | ||
"idf.buildPath", | ||
workspaceRoot | ||
) as string; | ||
const projectName = await getProjectName(buildDirPath); | ||
const projectElfFile = `${path.join(buildDirPath, projectName)}.elf`; | ||
const debugAdapterConfig = { | ||
currentWorkspace: workspaceRoot, | ||
elfFile: projectElfFile, | ||
} as IDebugAdapterConfig; | ||
debugAdapterManager.configureAdapter(debugAdapterConfig); | ||
const openOCDConfig: IOpenOCDConfig = { | ||
workspace: workspaceRoot, | ||
} as IOpenOCDConfig; | ||
openOCDManager.configureServer(openOCDConfig); | ||
} | ||
if (typeof workspaceRoot === undefined) { | ||
workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]); | ||
await getIdfTargetFromSdkconfig( | ||
workspaceRoot, | ||
statusBarItems["target"] | ||
); | ||
const coverageOptions = getCoverageOptions(workspaceRoot); | ||
covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions); | ||
} | ||
const buildDirPath = idfConf.readParameter( | ||
"idf.buildPath", | ||
workspaceRoot | ||
) as string; | ||
const projectName = await getProjectName(buildDirPath); | ||
const projectElfFile = `${path.join(buildDirPath, projectName)}.elf`; | ||
const debugAdapterConfig = { | ||
currentWorkspace: workspaceRoot, | ||
elfFile: projectElfFile, | ||
} as IDebugAdapterConfig; | ||
debugAdapterManager.configureAdapter(debugAdapterConfig); | ||
const openOCDConfig: IOpenOCDConfig = { | ||
workspace: workspaceRoot, | ||
} as IOpenOCDConfig; | ||
openOCDManager.configureServer(openOCDConfig); | ||
} | ||
ConfserverProcess.dispose(); | ||
}); | ||
ConfserverProcess.dispose(); | ||
}) | ||
); | ||
|
||
vscode.debug.onDidTerminateDebugSession((e) => { | ||
if (isOpenOCDLaunchedByDebug && !isDebugRestarted) { | ||
|
@@ -3666,6 +3671,43 @@ export async function activate(context: vscode.ExtensionContext) { | |
new HintHoverProvider(treeDataProvider) | ||
) | ||
); | ||
checkAndNotifyMissingCompileCommands(); | ||
} | ||
|
||
function checkAndNotifyMissingCompileCommands() { | ||
if (vscode.workspace.workspaceFolders) { | ||
vscode.workspace.workspaceFolders.forEach(async (folder) => { | ||
try { | ||
const isIdfProject = utils.checkIsProjectCmakeLists(folder.uri.fsPath); | ||
if (isIdfProject) { | ||
const buildDirPath = idfConf.readParameter( | ||
"idf.buildPath", | ||
workspaceRoot | ||
) as string; | ||
const compileCommandsPath = path.join( | ||
radurentea marked this conversation as resolved.
Show resolved
Hide resolved
|
||
buildDirPath, | ||
"compile_commands.json" | ||
); | ||
const compileCommandsExists = await pathExists(compileCommandsPath); | ||
|
||
if (!compileCommandsExists) { | ||
showInfoNotificationWithAction( | ||
vscode.l10n.t( | ||
"compile_commands.json is missing. This may cause errors with code analysis extensions." | ||
), | ||
vscode.l10n.t("Generate compile_commands.json"), | ||
() => vscode.commands.executeCommand("espIdf.idfReconfigureTask") | ||
); | ||
} | ||
} | ||
} catch (error) { | ||
const msg = error.message | ||
? error.message | ||
: "Error checking for compile_commands.json file."; | ||
Logger.error(msg, error, "extension compileCommandsExists"); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
async function getFrameworksPickItems() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as vscode from "vscode"; | ||
|
||
type NotificationAction = () => Thenable<unknown> | Promise<void> | void; | ||
|
||
/** | ||
* Shows an information notification with a button that executes a custom action when clicked. | ||
* @param {string} infoMessage - The information message to display. | ||
* @param {string} buttonLabel - The label for the button. | ||
* @param {NotificationAction} action - The action to perform when the button is clicked. | ||
* @returns {Promise<void>} - A promise that resolves when the notification is shown and handled. | ||
*/ | ||
export async function showInfoNotificationWithAction( | ||
infoMessage: string, | ||
buttonLabel: string, | ||
action: NotificationAction | ||
): Promise<void> { | ||
const selectedOption = await vscode.window.showInformationMessage( | ||
infoMessage, | ||
buttonLabel | ||
); | ||
|
||
if (selectedOption === buttonLabel) { | ||
await Promise.resolve(action()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rebase is removing changes from #1266 which are implemented in master.
Please update.