Skip to content

Commit

Permalink
Merge pull request #111 from Avaiga/bug/#110-work-on-empty-files
Browse files Browse the repository at this point in the history
#110 work on empty files
  • Loading branch information
FredLL-Avaiga authored Dec 22, 2022
2 parents f5ff1e2 + 1295665 commit 4785f88
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Taipy Studio Configuration Builder",
"description": "Visual Studio Code extension for Taipy: Configuration Builder",
"publisher": "Avaiga",
"version": "0.0.5",
"version": "0.0.6",
"homepage": "https://github.com/Avaiga/taipy-studio.git",
"repository": {
"type": "git",
Expand Down
5 changes: 5 additions & 0 deletions core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export class Context {
}

private revealConfigNodesInTrees() {
this.unselectConfigNode();
this.treeProviders.forEach((p, idx) => {
const nodeType = p.getNodeType();
const lastSelectedUri = this.selectionCache[nodeType];
Expand Down Expand Up @@ -215,6 +216,10 @@ export class Context {
return workspace.openTextDocument(getOriginalUri(uri));
}

private async unselectConfigNode(): Promise<void> {
this.configDetailsView.setEmptyContent();
}

private async selectConfigNode(nodeType: string, name: string, configNode: object, uri: Uri, reveal = true): Promise<void> {
let updateCache = false;
if (reveal || this.selectionCache.lastView === nodeType) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/editors/ConfigEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export class ConfigEditorProvider implements CustomTextEditorProvider {
}

private async applyEdits(uri: Uri, edits: TextEdit[]) {
if (edits.length) {
if (edits?.length) {
const we = new WorkspaceEdit();
we.set(uri, edits);
return workspace.applyEdit(we);
Expand Down Expand Up @@ -357,7 +357,7 @@ export class ConfigEditorProvider implements CustomTextEditorProvider {
private async getNodeName(doc: TextDocument, nodeType: string, addNodeToActiveDiagram = true) {
const symbols = this.taipyContext.getSymbols(doc.uri.toString());
const typeSymbol = getSymbol(symbols, nodeType);
const nodeName = typeSymbol.children
const nodeName = (typeSymbol?.children || [])
.filter(s => s.name.toLowerCase().startsWith(nodeType.toLowerCase()))
.sort()
.reduce((pv, s) => {
Expand All @@ -375,7 +375,7 @@ export class ConfigEditorProvider implements CustomTextEditorProvider {
if (!value || /[\s\.]/.test(value) || value.toLowerCase() === "default") {
return l10n.t("Entity {0} Name should not contain space, '.' or be empty or be default '{1}'", nodeType, value);
}
if (typeSymbol.children.some(s => s.name.toLowerCase() === value.toLowerCase())) {
if (typeSymbol?.children.some(s => s.name.toLowerCase() === value.toLowerCase())) {
return l10n.t("Another {0} entity has the name {1}", nodeType, value);
}
return undefined as string;
Expand Down
6 changes: 6 additions & 0 deletions core/src/providers/ConfigDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export class ConfigDetailsView implements WebviewViewProvider {
private docListener(textDocument: TextDocument) {
if (isUriEqual(this.configUri, textDocument.uri)) {
const symbols = this.taipyContext.getSymbols(this.configUri.toString());
if (!symbols) {
this.setEmptyContent();
}
const nameSymbol = getSymbol(symbols, this.nodeType, this.nodeName);
const node = getNodeFromSymbol(textDocument, nameSymbol);
this._view?.webview.postMessage({
Expand All @@ -108,6 +111,9 @@ export class ConfigDetailsView implements WebviewViewProvider {

private async editProperty(nodeType: string, nodeName: string, propertyName?: string, propertyValue?: string | string[]) {
const symbols = this.taipyContext.getSymbols(this.configUri.toString());
if (!symbols) {
return;
}
const insert = !propertyName;
let propertyRange: Range;
if (insert) {
Expand Down
4 changes: 3 additions & 1 deletion core/src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const linkNodeTypes = [DataNode, Task, Pipeline];
export const reportInconsistencies = (doc: TextDocument, symbols: Array<DocumentSymbol>, schemaErrors: ErrorObject[] | null) => {
const nodeIds = new Set<string>();
const diagnostics = [] as Diagnostic[];
if (Array.isArray(symbols)) {
// Check the existence of the linked elements
symbols.forEach((symbol) => {
const childType = getChildType(symbol.name);
Expand Down Expand Up @@ -62,7 +63,8 @@ export const reportInconsistencies = (doc: TextDocument, symbols: Array<Document
});
})
);
schemaErrors &&
}
Array.isArray(schemaErrors) &&
schemaErrors.forEach((err) => {
const paths = err.instancePath.split("/").filter((p) => p);
const symbol = getSymbol(symbols, ...paths);
Expand Down
2 changes: 1 addition & 1 deletion core/webviews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "taipy-studio-webviews",
"description": "Components for Visual Studio Code extension for Taipy",
"publisher": "Avaiga",
"version": "0.0.5",
"version": "0.0.6",
"categories": [
"Other"
],
Expand Down

0 comments on commit 4785f88

Please sign in to comment.