-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce project loading for workspaces
It's because now server-side CLI deprecated the folder option
- Loading branch information
Showing
12 changed files
with
3,480 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
build/** | ||
src/** | ||
tests/** | ||
coverage/** | ||
out/** | ||
tsconfig.json | ||
extension.webpack.config.js | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Eclipse Che Port for Visual Studio Code | ||
|
||
**Notice:** This extension is bundled with Visual Studio Code. It can be disabled but not uninstalled. | ||
|
||
## Features | ||
|
||
This extension loads the correct project folder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* eslint-disable header/header */ | ||
/* | ||
* Copyright (c) 2022 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
|
||
/** | ||
* Mock of vscode module | ||
* @author Florent Benoit | ||
*/ | ||
const vscode: any = {}; | ||
export class EventEmitter { | ||
constructor() { } | ||
fire() { } | ||
} | ||
|
||
export enum TreeItemCollapsibleState { | ||
None, | ||
Collapsed, | ||
Expanded, | ||
} | ||
|
||
vscode.extensions = {}; | ||
const extensionsExports = {}; | ||
|
||
vscode.extensions.setExtensionExport = (name: string, value: any): void => { | ||
(extensionsExports as any)[name] = value; | ||
}; | ||
|
||
vscode.extensions.getExtension = (name: string): any => { | ||
return { | ||
activate: jest.fn(), | ||
exports: (extensionsExports as any)[name], | ||
}; | ||
}; | ||
|
||
|
||
vscode.EventEmitter = EventEmitter; | ||
vscode.TreeItemCollapsibleState = TreeItemCollapsibleState; | ||
module.exports = vscode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2022 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
***********************************************************************/ | ||
|
||
/* eslint-disable header/header */ | ||
|
||
//@ts-check | ||
|
||
'use strict'; | ||
|
||
const withDefaults = require('../shared.webpack.config'); | ||
|
||
module.exports = withDefaults({ | ||
context: __dirname, | ||
resolve: { | ||
mainFields: ['module', 'main'] | ||
}, | ||
entry: { | ||
extension: './src/extension.ts', | ||
} | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"name": "project", | ||
"displayName": "%displayName%", | ||
"description": "%description%", | ||
"publisher": "eclipse-che", | ||
"license": "EPL-2.0", | ||
"version": "0.0.1", | ||
"engines": { | ||
"vscode": "^1.63.0" | ||
}, | ||
"icon": "images/icon.png", | ||
"categories": [ | ||
"Other" | ||
], | ||
"activationEvents": [ | ||
"*" | ||
], | ||
"capabilities": { | ||
"virtualWorkspaces": true, | ||
"untrustedWorkspaces": { | ||
"supported": true | ||
} | ||
}, | ||
"main": "./out/extension.js", | ||
"scripts": { | ||
"compile": "gulp compile-extension:che-project", | ||
"watch": "gulp watch-extension:che-project", | ||
"vscode:prepublish": "npm run compile", | ||
"test": "jest", | ||
"lint:fix": "eslint --fix --cache=true --no-error-on-unmatched-pattern=true \"{src,tests}/**/*.{ts,tsx}\"" | ||
}, | ||
"dependencies": { | ||
"fs-extra": "^10.0.0", | ||
"vscode-nls": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"jest": "27.3.1", | ||
"ts-jest": "27.0.7", | ||
"@types/fs-extra": "^9.0.13", | ||
"@types/jest": "^27.4.0", | ||
"@types/js-yaml": "^4.0.5", | ||
"@types/node": "14.x" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/che-incubator/che-code.git" | ||
}, | ||
"extensionDependencies": [ | ||
"eclipse-che.api" | ||
], | ||
"jest": { | ||
"collectCoverage": true, | ||
"collectCoverageFrom": [ | ||
"src/**/*.ts" | ||
], | ||
"coverageDirectory": "./coverage", | ||
"transform": { | ||
"^.+\\.tsx?$": "ts-jest" | ||
}, | ||
"modulePathIgnorePatterns": [ | ||
"<rootDir>/dist" | ||
], | ||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"tsx", | ||
"js", | ||
"jsx", | ||
"json" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"displayName": "Eclipse Che Project", | ||
"description": "Open project automatically at startup if no project is provided" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2022 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
***********************************************************************/ | ||
|
||
/* eslint-disable header/header */ | ||
|
||
import * as vscode from 'vscode'; | ||
|
||
export async function activate(_context: vscode.ExtensionContext): Promise<void> { | ||
const output = vscode.window.createOutputChannel('Che Project'); | ||
// check if there are projects already defined | ||
// if true, exit | ||
const projects = vscode.workspace.workspaceFolders; | ||
if (projects) { | ||
output.appendLine('Found existing projects in the workspace, skipping the sequence'); | ||
return; | ||
} | ||
|
||
// open the project if found one | ||
const workspacePath = await getCheWorkspacePath(output); | ||
if (workspacePath) { | ||
output.appendLine(`Opening the folder... ${workspacePath.toString()}`); | ||
await vscode.commands.executeCommand('vscode.openFolder', workspacePath, { forceReuseWindow: true }); | ||
} else { | ||
output.appendLine('no workspace found'); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Check if PROJECTS_ROOT is defined. | ||
* If there is no folders inside, return PROJECTS_ROOT directory | ||
* If there is a file named eclipse-che.code-workspace inside PROJECTS_ROOT, return it | ||
* if there is only one folder: if there is one code-workspace file inside, return it else return this unique folder | ||
* if there are more than one folder, create a eclipse-che.code-workspace file and return that folder | ||
*/ | ||
export async function getCheWorkspacePath(output: vscode.OutputChannel): Promise<vscode.Uri | undefined> { | ||
if (process.env.PROJECTS_ROOT) { | ||
const projectsRoot = process.env.PROJECTS_ROOT; | ||
const projectsRootUri = vscode.Uri.file(projectsRoot); | ||
|
||
// list everything from that directory | ||
const children = await vscode.workspace.fs.readDirectory(projectsRootUri); | ||
|
||
// do we have a eclipse-che.code-workspace file there ? | ||
const cheCodeWorkspace = children.filter(child => child[1] === vscode.FileType.Directory).find(child => child[0] === 'eclipse-che.code-workspace'); | ||
if (cheCodeWorkspace) { | ||
output.appendLine('Found a eclipse-che.code-workspace file in the projects root, using it'); | ||
return vscode.Uri.joinPath(projectsRootUri, cheCodeWorkspace[0]); | ||
} | ||
|
||
// no, so grab all folders inside PROJECTS_ROOT and add them to a file | ||
const folders = children.filter(child => child[1] === vscode.FileType.Directory); | ||
|
||
// no folder in PROJECTS_ROOT, open the default folder | ||
if (folders.length === 0) { | ||
output.appendLine(`No folder found in the projects root, opening the default projects root folder ${projectsRoot}`); | ||
return projectsRootUri; | ||
} else if (folders.length === 1) { | ||
// check if we have a workspace in that folder. | ||
// if yes, use it | ||
const folderPath = vscode.Uri.joinPath(projectsRootUri, folders[0][0]); | ||
const projectsFiles = await vscode.workspace.fs.readDirectory(folderPath); | ||
const anyCodeWorkspaces = projectsFiles.filter(child => child[1] === vscode.FileType.File).filter(file => file[0].endsWith('.code-workspace')); | ||
if (anyCodeWorkspaces.length === 1) { | ||
output.appendLine('Found a single folder with a single code-workspace file in it, using it'); | ||
const anyCodeWorkspace = anyCodeWorkspaces[0][0]; | ||
output.appendLine(`anyCodeWorkspace = ${anyCodeWorkspace.toString()}`); | ||
// use that file | ||
const workspacePath = vscode.Uri.joinPath(folderPath, anyCodeWorkspace); | ||
output.appendLine(`workspacePath = ${workspacePath.toString()}`); | ||
return workspacePath; | ||
} | ||
output.appendLine('Found a single folder with no code-workspace file in it, using folder as it is'); | ||
const workspacePath = vscode.Uri.joinPath(projectsRootUri, folders[0][0]); | ||
output.appendLine(`folder is ${folders[0][0]}, workspacePath = ${workspacePath.toString()}`); | ||
return workspacePath; | ||
} else { | ||
const eclipseCheCodeWorkspace = { | ||
folders: folders.map(folder => { return { path: folder[0] } }) | ||
}; | ||
output.appendLine('Found multiple folders, creating a eclipse-che.code-workspace file in the projects root'); | ||
const eclipseCheCodeWorkspacePath = vscode.Uri.joinPath(projectsRootUri, 'eclipse-che.code-workspace'); | ||
await vscode.workspace.fs.writeFile(eclipseCheCodeWorkspacePath, Buffer.from(JSON.stringify(eclipseCheCodeWorkspace, undefined, 2), 'utf-8')); | ||
return eclipseCheCodeWorkspacePath; | ||
} | ||
} | ||
// return empty if not found | ||
return undefined; | ||
|
||
} | ||
|
||
|
||
export function deactivate(): void { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "./out", | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"types": [ | ||
"node", | ||
"jest", | ||
"reflect-metadata" | ||
] | ||
}, | ||
"include": [ | ||
"src/**/*", | ||
"../../src/vscode-dts/vscode.d.ts", | ||
] | ||
} |
Oops, something went wrong.