-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Generate unique ID across view files in an application (#719)
* feat: support unique ID generation across a project * fix: validate all opened documents * fix: validate all opened documents on file delete or rename * fix: add and adapt tests * fix: add change set * fix: failing test and clean up * fix: remove dependency * fix: remove nyc. jest has build in coverage * fix: remove nyc cofig.js * refactor: cache control in context and avoid context manipulation * fix: change set * fix: escpe SonarCloud reporting * fix: snoare cloud issues * fix: review comments and small improvment * fix: performance optimization * chore: inclusive language
- Loading branch information
1 parent
bcd5523
commit d6ceeaa
Showing
66 changed files
with
1,960 additions
and
933 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch | ||
"vscode-ui5-language-assistant": patch | ||
"@ui5-language-assistant/context": patch | ||
"@ui5-language-assistant/language-server": patch | ||
"@ui5-language-assistant/logic-utils",: patch | ||
"@ui5-language-assistant/user-facing-text": patch | ||
"@ui5-language-assistant/xml-views-completion": patch | ||
"@ui5-language-assistant/xml-views-definition": patch | ||
"@ui5-language-assistant/xml-views-quick-fix": patch | ||
"@ui5-language-assistant/xml-views-tooltip": patch | ||
"@ui5-language-assistant/xml-views-validation": patch | ||
--- | ||
|
||
feat: support unique id generation across view files in an application |
This file was deleted.
Oops, something went wrong.
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
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,78 @@ | ||
import { FileChangeType } from "vscode-languageserver/node"; | ||
import { cache } from "../api"; | ||
import { ControlIdLocation } from "../types"; | ||
import { IdsCollectorVisitor } from "./ids-collector"; | ||
import { accept } from "@xml-tools/ast"; | ||
|
||
/** | ||
* Process control ids | ||
* | ||
* @param param parameter object | ||
* @param param.manifestPath path to manifest.json file | ||
* @param param.documentPath path to xml view file | ||
*/ | ||
function processControlIds(param: { | ||
manifestPath: string; | ||
documentPath: string; | ||
content?: string; | ||
}): void { | ||
const { documentPath, manifestPath, content } = param; | ||
// check cache | ||
if (Object.keys(cache.getControlIds(manifestPath)).length > 0) { | ||
if (content) { | ||
// for current document, re-collect and re-assign it to avoid cache issue | ||
cache.setControlIdsForViewFile({ | ||
manifestPath, | ||
documentPath, | ||
operation: FileChangeType.Created, | ||
}); | ||
} | ||
return; | ||
} | ||
|
||
// build fresh | ||
const ctrIds: Record<string, Map<string, ControlIdLocation[]>> = {}; | ||
const viewFiles = cache.getViewFiles(manifestPath); | ||
const files = Object.keys(viewFiles); | ||
for (const docPath of files) { | ||
const idCollector = new IdsCollectorVisitor(docPath); | ||
accept(viewFiles[docPath], idCollector); | ||
ctrIds[docPath] = idCollector.getControlIds(); | ||
} | ||
cache.setControlIds(manifestPath, ctrIds); | ||
} | ||
|
||
/** | ||
* Get control ids of all xml files. | ||
* | ||
* @param param parameter object | ||
* @param param.manifestPath path to manifest.json file | ||
* @param param.documentPath path to xml view file | ||
* @returns merged control ids of all xml files | ||
*/ | ||
export function getControlIds(param: { | ||
manifestPath: string; | ||
documentPath: string; | ||
content?: string; | ||
}): Map<string, ControlIdLocation[]> { | ||
const { manifestPath } = param; | ||
|
||
processControlIds(param); | ||
|
||
const allDocumentsIds = cache.getControlIds(manifestPath); | ||
const keys = Object.keys(allDocumentsIds); | ||
|
||
const mergedIds: Map<string, ControlIdLocation[]> = new Map(); | ||
for (const doc of keys) { | ||
const ids = allDocumentsIds[doc]; | ||
for (const [id, location] of ids) { | ||
const existing = mergedIds.get(id); | ||
if (existing) { | ||
mergedIds.set(id, [...existing, ...location]); | ||
} else { | ||
mergedIds.set(id, location); | ||
} | ||
} | ||
} | ||
return mergedIds; | ||
} |
Oops, something went wrong.