File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed
Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 11import * as os from 'os' ;
22import * as fs from 'fs' ;
33import * as vscode from 'vscode' ;
4+ import * as path from 'path' ;
45
56import { getWorkspaceFolder } from '../api' ;
67import { 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 }
Original file line number Diff line number Diff line change @@ -192,7 +192,13 @@ export function writeWorkspaceJson(data: any) {
192192export 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) {
201207export 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}
You can’t perform that action at this time.
0 commit comments