Skip to content

Commit cd968fe

Browse files
authored
Merge pull request #22 from BernardXiong/relative_path
Relative path
2 parents 9d8460a + 58e1626 commit cd968fe

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ RT-Thread VSCode扩展是一款专为RT-Thread及RT-Thread Smart (版本>5.2.0)
88

99
### 版本说明
1010

11+
**v0.4.12**
12+
- 加入RT-Thread ELF文件符号分析的功能;
13+
- 调整界面,web页面颜色样式可以跟随vscode的浅色/深色自动进行切换;
14+
- RT-Thread设置界面可以在UI上按照env脚本环境;
15+
- web页面有统一的RT-Thread logo banner;
16+
1117
**v0.4.11**
1218
- 添加Vue3、Element Plus的前端页面功能;
1319
- 更改RT-Thread Groups 到文件浏览视图,并增加编译图标按钮;
@@ -24,7 +30,7 @@ RT-Thread VSCode扩展是一款专为RT-Thread及RT-Thread Smart (版本>5.2.0)
2430

2531
### env安装说明
2632

27-
📢 如未安装,请点击<a href="https://github.com/RT-Thread/env" target="_blank">链接</a>了解如何进行安装。
33+
📢 如未安装,可以使用RT-Thread设置功能进行安装,也可以在命令行下自行安装:
2834

2935
**💻 Windows用户** 请使用PowerShell运行如下的命令进行安装:
3036

src/project/cmd.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as os from 'os';
22
import * as fs from 'fs';
33
import * as vscode from 'vscode';
4+
import * as path from 'path';
45

56
import { getWorkspaceFolder } from '../api';
67
import { executeCommand } from '../terminal';
@@ -55,7 +56,14 @@ export function setCurrentProject(arg: any) {
5556
// update workspace.json file
5657
let workspaceJson = readWorkspaceJson();
5758
if (workspaceJson) {
58-
workspaceJson.currentProject = arg.fn;
59+
const workspaceFolder = getWorkspaceFolder();
60+
let relativeProject = arg.fn;
61+
if (workspaceFolder && typeof arg.fn === 'string' && arg.fn.length > 0) {
62+
if (path.isAbsolute(arg.fn)) {
63+
relativeProject = path.relative(workspaceFolder, arg.fn);
64+
}
65+
}
66+
workspaceJson.currentProject = relativeProject;
5967
writeWorkspaceJson(workspaceJson);
6068
}
6169
}

src/webviews/project.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,13 @@ export function writeWorkspaceJson(data: any) {
192192
export function setCurrentProjectInWorkspace(project: string) {
193193
let workspaceJson = readWorkspaceJson();
194194
if (workspaceJson) {
195-
workspaceJson.currentProject = project;
195+
const workspaceFolder = getWorkspaceFolder();
196+
let relativeProject = project;
197+
if (workspaceFolder && path.isAbsolute(project)) {
198+
relativeProject = path.relative(workspaceFolder, project);
199+
}
200+
201+
workspaceJson.currentProject = relativeProject;
196202
writeWorkspaceJson(workspaceJson);
197203
}
198204
}
@@ -201,7 +207,20 @@ export function setCurrentProjectInWorkspace(project: string) {
201207
export function getCurrentProjectInWorkspace() {
202208
let workspaceJson = readWorkspaceJson();
203209
if (workspaceJson) {
204-
return workspaceJson.currentProject;
210+
const project = workspaceJson.currentProject;
211+
if (!project) {
212+
return null;
213+
}
214+
215+
// Backward compatible: if absolute, return it; if relative, resolve to absolute
216+
if (path.isAbsolute(project)) {
217+
return project;
218+
}
219+
220+
const workspaceFolder = getWorkspaceFolder();
221+
if (workspaceFolder) {
222+
return path.resolve(workspaceFolder, project);
223+
}
205224
}
206225
return null;
207226
}

0 commit comments

Comments
 (0)