Skip to content

Conversation

@HalfSweet
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings February 11, 2026 09:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates project path resolution so build/run-related features work when the project’s SConscript lives under project/hcpu or project/lcpu (instead of only project/).

Changes:

  • Add LCPU_SUBFOLDER constant and extend project detection to locate SConscript under project/hcpu, project/lcpu, or project/.
  • Extend getProjectInfo() to return the resolved project entry path (absolute + workspace-relative).
  • Update terminal cd behavior, board command generation, and clangd config generation to use the resolved project entry path.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/utils/projectUtils.ts Adds workspace root helper and logic to resolve the effective project entry directory based on where SConscript is found.
src/services/terminalService.ts Uses resolved project entry path when cd-ing the terminal into the project.
src/services/boardService.ts Uses resolved project entry path/relative path for build folder and board search path computations.
src/constants/index.ts Adds LCPU_SUBFOLDER = 'lcpu'.
src/commands/configCommands.ts Builds clangd --compile-commands-dir using the resolved project entry relative path.
Comments suppressed due to low confidence (2)

src/services/boardService.ts:166

  • projectPath falls back to an empty string when getProjectInfo() returns null. That makes subsequent path.relative(projectPath, ...) calculations use the process CWD (Node treats "" as "."), which can generate incorrect --board_search_path values for project_local/custom boards. Use a deterministic fallback (e.g. ${workspaceRoot}/project) or return/throw when projectInfo is missing so path.relative always has a valid base path.
    const projectInfo = getProjectInfo();
    const projectPath = projectInfo?.projectEntryPath || '';

    let boardSearchArg = '';
    const availableBoards = await this.discoverBoards();
    const currentBoard = availableBoards.find(b => b.name === boardName);

    if (currentBoard) {
      if (currentBoard.type === 'sdk') {
        boardSearchArg = '';
      } else if (currentBoard.type === 'project_local') {
        const projectLocalBoardsDir = path.dirname(currentBoard.path);
        const relativeToProject = path.relative(projectPath, projectLocalBoardsDir);
        boardSearchArg = ` --board_search_path="${relativeToProject}"`;
      } else if (currentBoard.type === 'custom') {
        const relativeToProject = path.relative(projectPath, currentBoard.path);
        boardSearchArg = ` --board_search_path="${path.dirname(relativeToProject)}"`;

src/services/boardService.ts:192

  • Same issue as getCompileCommand: falling back to projectPath = '' makes path.relative(projectPath, ...) compute relative paths from the process CWD, producing incorrect --board_search_path values when projectInfo is null. Prefer a deterministic fallback base path (workspaceRoot/project) or fail early if no project can be resolved.
    const projectInfo = getProjectInfo();
    const projectPath = projectInfo?.projectEntryPath || '';

    let boardSearchArg = '';
    const availableBoards = await this.discoverBoards();
    const currentBoard = availableBoards.find(b => b.name === boardName);

    if (currentBoard && currentBoard.type !== 'sdk') {
      if (currentBoard.type === 'project_local') {
        const projectLocalBoardsDir = path.dirname(currentBoard.path);
        const relativeToProject = path.relative(projectPath, projectLocalBoardsDir);
        boardSearchArg = ` --board_search_path="${relativeToProject}"`;
      } else if (currentBoard.type === 'custom') {
        const relativeToProject = path.relative(projectPath, currentBoard.path);
        boardSearchArg = ` --board_search_path="${path.dirname(relativeToProject)}"`;
      }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +44 to +46
path.join(projectPath, SCONSCRIPT_FILE),
path.join(projectPath, HCPU_SUBFOLDER, SCONSCRIPT_FILE),
path.join(projectPath, LCPU_SUBFOLDER, SCONSCRIPT_FILE)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolveProjectEntry() checks candidates in the order [project/hcpu, project/lcpu, project], but the failure log message is built from getSconscriptCandidatePaths() which returns [project, project/hcpu, project/lcpu]. This makes the "Checked:" list inaccurate and can mislead debugging. Align the candidate order (either change projectCandidates or getSconscriptCandidatePaths).

Suggested change
path.join(projectPath, SCONSCRIPT_FILE),
path.join(projectPath, HCPU_SUBFOLDER, SCONSCRIPT_FILE),
path.join(projectPath, LCPU_SUBFOLDER, SCONSCRIPT_FILE)
path.join(projectPath, HCPU_SUBFOLDER, SCONSCRIPT_FILE),
path.join(projectPath, LCPU_SUBFOLDER, SCONSCRIPT_FILE),
path.join(projectPath, SCONSCRIPT_FILE)

Copilot uses AI. Check for mistakes.
Copy link

@livewithme livewithme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以修改一下

: '';
const projectPath = path.join(workspaceRoot, 'project');
const projectInfo = getProjectInfo();
const projectPath = projectInfo?.projectEntryPath || '';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const projectPath = this.getProjectFolderPath();

: '';
const projectPath = path.join(workspaceRoot, 'project');
const projectInfo = getProjectInfo();
const projectPath = projectInfo?.projectEntryPath || '';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

统一调用
const projectPath = this.getProjectFolderPath();

const workspaceRoot = workspaceFolders[0].uri.fsPath;
const projectPath = path.join(workspaceRoot, PROJECT_SUBFOLDER);
const projectInfo = getProjectInfo();
const projectPath = projectInfo?.projectEntryPath || path.join(workspaceRoot, PROJECT_SUBFOLDER);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 切换到项目目录
const projectInfo = getProjectInfo();
const projectPath = projectInfo?.projectEntryPath;
if (!projectPath) {
  // 提示一下错误
  this.logService.error('[terminalService] Project entry path not found');
  return terminal;
}
terminal.sendText(`cd "${projectPath}"`);
this.logService.debug(`Changed terminal directory to: ${projectPath}`); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants