-
Notifications
You must be signed in to change notification settings - Fork 111
Deprecate current.project.path variable #585
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,17 +9,17 @@ | |
**********************************************************************/ | ||
|
||
import { injectable } from 'inversify'; | ||
import Uri from 'vscode-uri'; | ||
import * as che from '@eclipse-che/plugin'; | ||
import * as theia from '@theia/plugin'; | ||
import * as startPoint from '../task-plugin-backend'; | ||
|
||
const VARIABLE_NAME = 'current.project.path'; | ||
const SELECTED_CONTEXT_COMMAND = 'theia.plugin.workspace.selectedContext'; | ||
const PROJECTS_ROOT_VARIABLE = 'CHE_PROJECTS_ROOT'; | ||
const ERROR_MESSAGE_TEMPLATE = 'Can not resolve \'current.project.path\' variable.'; | ||
/** | ||
* Contributes the variable for getting path for current project as a relative path to the first directory under the root workspace. | ||
* | ||
* @deprecated will be removed soon. Use ${workspaceFolder} macro instead. | ||
*/ | ||
@injectable() | ||
export class ProjectPathVariableResolver { | ||
|
@@ -38,33 +38,7 @@ export class ProjectPathVariableResolver { | |
return this.onError('Projects root is not set'); | ||
} | ||
|
||
const selections = await theia.commands.executeCommand<Uri[]>(SELECTED_CONTEXT_COMMAND); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should not remove this logic if at the moment it's just deprecated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This command relies on the current selection. When workspace opens at first time, the selection is not initialized and we're getting error message There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that there are bugs related to using this variable if user has incorrect selection, that's why we decided to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our samples don't use this macro. If user uses this macro in own devfile, it will broken anyway and command won't execute. There will be created another PR into docs that describes, that fact, that this macro is deprecated and has to be replaced with another one. So, yes, this changes proposal changes behavior of the flow for this macro. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. steps to reproduce:
output:
output: |
||
if (!selections || selections.length < 1) { | ||
return this.onError('Please select a project.'); | ||
} | ||
|
||
const selection = selections[0]; | ||
const selectionPath = selection.path; | ||
const workspaceFolder = theia.workspace.getWorkspaceFolder(theia.Uri.file(selectionPath)); | ||
if (!workspaceFolder) { | ||
return this.onError('Selection doesn\'t match any workspace folder.'); | ||
} | ||
|
||
const workspaceFolderPath = workspaceFolder.uri.path; | ||
if (workspaceFolderPath === this.projectsRoot) { | ||
const splittedSelectionUri = selectionPath.substring(workspaceFolderPath.length).split('/'); | ||
const project = splittedSelectionUri.shift() || splittedSelectionUri.shift(); | ||
|
||
this.isResolved = true; | ||
return `${this.projectsRoot}/${project}`; | ||
} | ||
|
||
if (workspaceFolderPath.startsWith(this.projectsRoot)) { | ||
this.isResolved = true; | ||
return workspaceFolderPath; | ||
} | ||
|
||
return this.onError('The selection isn\'t under the current workspace root folder.'); | ||
return this.projectsRoot; | ||
} | ||
|
||
private createVariable(): che.Variable { | ||
|
@@ -76,10 +50,10 @@ export class ProjectPathVariableResolver { | |
}; | ||
} | ||
|
||
private onError(error?: string) { | ||
private onError(error: string) { | ||
this.isResolved = false; | ||
|
||
const errorMessage = error ? `${ERROR_MESSAGE_TEMPLATE} ${error}` : ERROR_MESSAGE_TEMPLATE; | ||
const errorMessage = `${ERROR_MESSAGE_TEMPLATE} ${error}`; | ||
theia.window.showErrorMessage(errorMessage); | ||
return Promise.reject(errorMessage); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not enough just replace
${current.project.path}
by${workspaceFolder}
. Instead user should use${workspaceFolder}/theia
for exampleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There will be created PR into docs that describes that fact, that this macro is deprecated and has to be replaced