Skip to content

[vscode] Add VSCode workspace generation for vscode_extension. #10462

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

Merged
merged 3 commits into from
Jul 8, 2025

Conversation

BernardXiong
Copy link
Member

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

当使用vscode(及扩展)打开RT-Thread目录时,可以生成一定的类workspace配置,只关注感兴趣的bsp,把其他无关bsp自动排除。

你的解决方案是什么 (what is your solution)

在RT-Thread根目录下使用scons生成适合的配置。<注:若类似stm32这样的bsp,需要自行先解决pkgs --update的问题>

请提供验证的bsp和config (provide the config and bsp)

  • BSP: qemu-vexpress-a9,qemu其他bsp,stm32f412-st-nucleo <需确保手工完成pkgs --update更新>
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/workflows/bsp_buildings.yml 详细请参考链接BSP自查

Copilot

This comment was marked as outdated.

@BernardXiong BernardXiong requested a review from Copilot July 6, 2025 15:10
Copy link
Contributor

@Copilot 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 introduces a dedicated VSCode workspace generator for the vscode_extension, adding support for .vscode/c_cpp_properties.json and .vscode/settings.json, and wiring it into the SCons build workflow as a new vsc_workspace target.

  • Added GenerateVSCodeWorkspace and helper find_rtconfig_dirs in tools/targets/vsc.py
  • Updated CLI options to include vsc_workspace in tools/options.py
  • Registered the new vsc_workspace SCons target in tools/building.py

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tools/targets/vsc.py New workspace generation functions; output of C/C++ properties and settings JSON
tools/options.py Extended --target help to list vsc_workspace
tools/building.py Exported default env and added vsc_workspace target handler
Comments suppressed due to low confidence (1)

tools/targets/vsc.py:338

  • Docstring claims 'up to 4 levels deep' but the implementation only looks at immediate children and their parent. Update the doc or implement deeper recursion to match.
    Search for subdirectories containing 'rtconfig.h' under 'bsp_dir' (up to 4 levels deep), excluding 'project_dir'.

Comment on lines +352 to +353
list = os.listdir(bsp_dir)
for item in list:
Copy link
Preview

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

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

[nitpick] Variable name 'list' shadows the built-in type. Rename it (e.g., to 'entries' or 'items') to avoid confusion.

Suggested change
list = os.listdir(bsp_dir)
for item in list:
entries = os.listdir(bsp_dir)
for item in entries:

Copilot uses AI. Check for mistakes.

Comment on lines +400 to +403
bsp_dir = os.path.join(cwd, workspace_data.get('bsps', {}).get('folder', ''))
if not bsp_dir:
print('No BSP directories found in the workspace file, skip generating.')
return
Copy link
Preview

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

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

This check never triggers because os.path.join(cwd, '') returns cwd, not an empty string. Consider verifying the 'folder' key exists or use os.path.exists to detect missing BSP directory.

Suggested change
bsp_dir = os.path.join(cwd, workspace_data.get('bsps', {}).get('folder', ''))
if not bsp_dir:
print('No BSP directories found in the workspace file, skip generating.')
return
folder = workspace_data.get('bsps', {}).get('folder')
if not folder:
print('No BSP folder specified in the workspace file, skip generating.')
return
bsp_dir = os.path.join(cwd, folder)
if not os.path.exists(bsp_dir):
print(f'BSP directory "{bsp_dir}" does not exist, skip generating.')
return

Copilot uses AI. Check for mistakes.

Comment on lines +404 to +406
except Exception as e:
print('Error reading workspace file, skip generating.')
return
Copy link
Preview

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

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

Catching the base Exception silently may mask errors. Catch more specific exceptions (e.g., IOError, json.JSONDecodeError) or log the exception details for easier debugging.

Suggested change
except Exception as e:
print('Error reading workspace file, skip generating.')
return
except FileNotFoundError as e:
print(f'Workspace file not found: {e}, skip generating.')
return
except json.JSONDecodeError as e:
print(f'Error decoding JSON from workspace file: {e}, skip generating.')
return

Copilot uses AI. Check for mistakes.

@illustriousness
Copy link
Contributor

这个太可以了

@Rbb666 Rbb666 merged commit e57605f into RT-Thread:master Jul 8, 2025
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants