提交 84d92cd7 编写于 作者: B Benjamin Pasero

Allow to open workspace files that are invalid JSON files (fixes #33502)

上级 d55445cf
......@@ -20,6 +20,7 @@ import { isEqual, isEqualOrParent } from 'vs/base/common/paths';
import { coalesce } from 'vs/base/common/arrays';
import { createHash } from 'crypto';
import URI from 'vs/base/common/uri';
import * as json from 'vs/base/common/json';
// TODO@Ben migration
export interface ILegacyStoredWorkspace {
......@@ -109,7 +110,7 @@ export class WorkspacesMainService implements IWorkspacesMainService {
// Parse workspace file
let storedWorkspace: IStoredWorkspace;
try {
storedWorkspace = JSON.parse(contents);
storedWorkspace = json.parse(contents); // use fault tolerant parser
} catch (error) {
throw new Error(`${path} cannot be parsed as JSON file (${error}).`);
}
......
......@@ -166,6 +166,17 @@ suite('WorkspacesMainService', () => {
});
});
test('resolveWorkspaceSync (support invalid JSON via fault tolerant parsing)', done => {
return service.createWorkspace([process.cwd(), os.tmpdir()]).then(workspace => {
fs.writeFileSync(workspace.configPath, '{ "folders": [ { "path": "./ticino-playground/lib" } , ] }'); // trailing comma
const resolved = service.resolveWorkspaceSync(workspace.configPath);
assert.equal(URI.file(resolved.folders[0].path).fsPath, URI.file(path.join(path.dirname(workspace.configPath), 'ticino-playground', 'lib')).fsPath);
done();
});
});
test('saveWorkspace (untitled)', done => {
let savedEvent: IWorkspaceSavedEvent;
const listener = service.onWorkspaceSaved(e => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册