Skip to content

Commit

Permalink
fix: snoare cloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
marufrasully committed Aug 19, 2024
1 parent a26da65 commit 504019e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 29 deletions.
21 changes: 7 additions & 14 deletions packages/context/src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import type { Manifest } from "@sap-ux/project-access";
import type { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types";
import { accept, type XMLDocument } from "@xml-tools/ast";
import type {
App,
ControlIdLocation,
DocumentPath,
Project,
YamlDetails,
} from "./types";
import { createDocumentAst } from "./utils";
import { IdsCollectorVisitor } from "./utils";
import type { App, ControlIdLocation, Project, YamlDetails } from "./types";
import { createDocumentAst, IdsCollectorVisitor } from "./utils";

type AbsoluteAppRoot = string;
type AbsoluteProjectRoot = string;
Expand All @@ -24,7 +17,7 @@ class Cache {
private viewFiles: Record<string, Record<string, XMLDocument>>;
private controlIds: Record<
string,
Record<DocumentPath, Map<string, ControlIdLocation[]>>
Record<string, Map<string, ControlIdLocation[]>>
>;
constructor() {
this.project = new Map();
Expand Down Expand Up @@ -144,13 +137,13 @@ class Cache {
/**
* Get entries of view files
*/
getViewFiles(manifestPath: string): Record<DocumentPath, XMLDocument> {
getViewFiles(manifestPath: string): Record<string, XMLDocument> {
return this.viewFiles[manifestPath] ?? {};
}

setViewFiles(
manifestPath: string,
viewFiles: Record<DocumentPath, XMLDocument>
viewFiles: Record<string, XMLDocument>
): void {
this.viewFiles[manifestPath] = viewFiles;
}
Expand Down Expand Up @@ -188,12 +181,12 @@ class Cache {
*/
getControlIds(
manifestPath: string
): Record<DocumentPath, Map<string, ControlIdLocation[]>> {
): Record<string, Map<string, ControlIdLocation[]>> {
return this.controlIds[manifestPath] ?? {};
}
setControlIds(
manifestPath: string,
controlIds: Record<DocumentPath, Map<string, ControlIdLocation[]>>
controlIds: Record<string, Map<string, ControlIdLocation[]>>
) {
this.controlIds[manifestPath] = controlIds;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/context/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export enum DirName {
Ext = "ext",
}

export type DocumentPath = string;
export interface ControlIdLocation extends Location {
offsetRange: OffsetRange;
}
Expand All @@ -34,7 +33,7 @@ export interface Context {
yamlDetails: YamlDetails;
services: Record<string, ServiceDetails>;
customViewId: string;
viewFiles: Record<DocumentPath, XMLDocument>;
viewFiles: Record<string, XMLDocument>;
controlIds: Map<string, ControlIdLocation[]>;
documentPath: string;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/context/src/utils/control-ids.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cache } from "../api";
import { ControlIdLocation, DocumentPath } from "../types";
import { ControlIdLocation } from "../types";
import { IdsCollectorVisitor } from "./ids-collector";
import { accept } from "@xml-tools/ast";

Expand All @@ -12,7 +12,7 @@ import { accept } from "@xml-tools/ast";
*/
function processControlIds(param: {
manifestPath: string;
documentPath: DocumentPath;
documentPath: string;
}): void {
const { documentPath, manifestPath } = param;
// check cache
Expand All @@ -27,7 +27,7 @@ function processControlIds(param: {
}

// build fresh
const ctrIds: Record<DocumentPath, Map<string, ControlIdLocation[]>> = {};
const ctrIds: Record<string, Map<string, ControlIdLocation[]>> = {};
const viewFiles = cache.getViewFiles(manifestPath);
const files = Object.keys(viewFiles);
for (const docPath of files) {
Expand All @@ -48,7 +48,7 @@ function processControlIds(param: {
*/
export function getControlIds(param: {
manifestPath: string;
documentPath: DocumentPath;
documentPath: string;
}): Map<string, ControlIdLocation[]> {
const { manifestPath } = param;

Expand Down
11 changes: 4 additions & 7 deletions packages/context/src/utils/view-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { isXMLView } from "@ui5-language-assistant/logic-utils";
import { parse, DocumentCstNode } from "@xml-tools/parser";
import { buildAst, XMLDocument } from "@xml-tools/ast";
import { cache } from "../cache";
import type { DocumentPath } from "../types";

export async function createDocumentAst(
documentPath: string,
Expand Down Expand Up @@ -34,11 +33,9 @@ async function processViewFiles(
const itemPath = join(base, item);
if (statSync(itemPath).isDirectory()) {
await processViewFiles(itemPath, files);
} else {
if (isXMLView(itemPath)) {
const ast = await createDocumentAst(itemPath);
files[itemPath] = ast;
}
} else if (isXMLView(itemPath)) {
const ast = await createDocumentAst(itemPath);
files[itemPath] = ast;
}
}
}
Expand All @@ -55,7 +52,7 @@ export async function getViewFiles(param: {
manifestPath: string;
documentPath: string;
content?: string;
}): Promise<Record<DocumentPath, XMLDocument>> {
}): Promise<Record<string, XMLDocument>> {
const { manifestPath, documentPath, content } = param;
if (Object.keys(cache.getViewFiles(manifestPath)).length > 0) {
if (content) {
Expand Down
3 changes: 1 addition & 2 deletions packages/logic-utils/src/utils/ui5-classes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { XMLElement } from "@xml-tools/ast";
import { resolveXMLNS } from "../api";
import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types";
import { SVG_NS, TEMPLATING_NS, XHTML_NS } from "../api";
import { SVG_NS, TEMPLATING_NS, XHTML_NS, resolveXMLNS } from "../api";
import { getUI5ClassByXMLElement } from "./xml-node-to-ui5-node";

// Heuristic to limit false positives by only checking tags starting with upper
Expand Down

0 comments on commit 504019e

Please sign in to comment.