Skip to content

Commit 3abf9a6

Browse files
authored
feat: user settings to control diagnostics reporting cross view files (#734)
* feat: user settings to control diagnostics reporting cross different view files * fix: add change set * fix: review comment * fix: update readme file
1 parent 3fa9e9b commit 3abf9a6

File tree

17 files changed

+225
-13
lines changed

17 files changed

+225
-13
lines changed

.changeset/ten-rivers-pull.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
3+
"vscode-ui5-language-assistant": patch
4+
"@ui5-language-assistant/xml-views-completion": patch
5+
"@ui5-language-assistant/language-server": patch
6+
"@ui5-language-assistant/settings": patch
7+
"@ui5-language-assistant/binding": patch
8+
"@ui5-language-assistant/context": patch
9+
"@ui5-language-assistant/fe": patch
10+
---
11+
12+
feat: User settings to control diagnostics reporting cross view files

packages/binding/test/unit/services/completion/aggregation-binding.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe("aggregation binding", () => {
3939
server: "off",
4040
},
4141
SplitAttributesOnFormat: true,
42+
LimitUniqueIdDiagnostics: false,
4243
};
4344

4445
beforeAll(async function () {

packages/binding/test/unit/services/completion/property-binding-info.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe("index", () => {
4444
server: "off",
4545
},
4646
SplitAttributesOnFormat: true,
47+
LimitUniqueIdDiagnostics: false,
4748
};
4849

4950
beforeAll(async function () {

packages/context/api.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ export type {
55
ManifestDetails,
66
YamlDetails,
77
ProjectKind,
8+
ControlIdLocation,
89
} from "./src/types";
910
export type { Manifest } from "@sap-ux/project-access";

packages/fe/test/unit/services/completion/providers/context-path.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe("contextPath attribute value completion", () => {
4545
server: "off",
4646
},
4747
SplitAttributesOnFormat: true,
48+
LimitUniqueIdDiagnostics: false,
4849
};
4950

5051
const annotationSnippetCDS = `

packages/fe/test/unit/services/completion/providers/filter-bar.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ describe("filterBar id attribute value completion", () => {
4343
server: "off",
4444
},
4545
SplitAttributesOnFormat: true,
46+
LimitUniqueIdDiagnostics: false,
4647
};
4748

4849
const annotationSnippetCDS = `

packages/fe/test/unit/services/completion/providers/meta-path.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ describe("metaPath attribute value completion", () => {
4848
server: "off",
4949
},
5050
SplitAttributesOnFormat: true,
51+
LimitUniqueIdDiagnostics: false,
5152
};
5253

5354
const annotationSnippetCDS = `

packages/language-server/src/server.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
getSettingsForDocument,
2525
setConfigurationSettings,
2626
Settings,
27+
getConfigurationSettings,
2728
} from "@ui5-language-assistant/settings";
2829
import { commands } from "@ui5-language-assistant/user-facing-text";
2930
import { ServerInitializationOptions } from "../api";
@@ -44,6 +45,7 @@ import {
4445
reactOnViewFileChange,
4546
reactOnPackageJson,
4647
isContext,
48+
Context,
4749
} from "@ui5-language-assistant/context";
4850
import { diagnosticToCodeActionFix } from "./quick-fix";
4951
import { executeCommand } from "./commands";
@@ -296,6 +298,28 @@ const validateIdsOfOpenDocuments = async (): Promise<void> => {
296298
connection.sendDiagnostics({ uri: document.uri, diagnostics });
297299
}
298300
};
301+
/**
302+
* Validates the IDs of the open document and sends the diagnostics to the client
303+
* @param {TextDocument} document - The open document to be validated
304+
* @param {Context} context - The context containing additional information
305+
* @returns {void}
306+
*/
307+
const validateIdsOfOpenDocument = (
308+
document: TextDocument,
309+
context: Context
310+
): void => {
311+
const idDiagnostics = getXMLViewIdDiagnostics({
312+
document,
313+
context,
314+
});
315+
let diagnostics = documentsDiagnostics.get(document.uri) ?? [];
316+
diagnostics = diagnostics.concat(idDiagnostics);
317+
318+
getLogger().trace("computed diagnostics", {
319+
diagnostics,
320+
});
321+
connection.sendDiagnostics({ uri: document.uri, diagnostics });
322+
};
299323

300324
async function validateOpenDocumentsOnDidChangeWatchedFiles(
301325
changes: FileEvent[]
@@ -391,7 +415,13 @@ documents.onDidChangeContent(async (changeEvent): Promise<void> => {
391415
context,
392416
});
393417
documentsDiagnostics.set(document.uri, diagnostics);
394-
await validateIdsOfOpenDocuments();
418+
const settings = getConfigurationSettings();
419+
const limitUniqueIdsDiagReport = settings.LimitUniqueIdDiagnostics;
420+
if (limitUniqueIdsDiagReport) {
421+
validateIdsOfOpenDocument(document, context);
422+
} else {
423+
await validateIdsOfOpenDocuments();
424+
}
395425
}
396426
});
397427

@@ -466,7 +496,7 @@ function ensureDocumentSettingsUpdated(resource: string): void {
466496
}
467497
}
468498

469-
connection.onDidChangeConfiguration((change) => {
499+
connection.onDidChangeConfiguration(async (change) => {
470500
getLogger().debug("`onDidChangeConfiguration` event");
471501
if (hasConfigurationCapability) {
472502
getLogger().trace("Reset all cached document settings");
@@ -487,9 +517,8 @@ connection.onDidChangeConfiguration((change) => {
487517
});
488518
setConfigurationSettings(ui5LangAssistSettings);
489519
}
490-
// In the future we might want to
491520
// re-validate the files related to the `cached document settings`.
492-
521+
await validateIdsOfOpenDocuments();
493522
// `setLogLevel` will ignore `undefined` values
494523
setLogLevel(change?.settings?.UI5LanguageAssistant?.logging?.level);
495524
});

packages/settings/api.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ export type Settings = CodeAssistSettings &
1313
TraceSettings &
1414
LoggingSettings &
1515
WebServerSettings &
16+
LimitUniqueIdDiagnostics &
1617
FormatterSettings;
1718

1819
export interface WebServerSettings {
1920
SAPUI5WebServer?: string;
2021
}
22+
export interface LimitUniqueIdDiagnostics {
23+
LimitUniqueIdDiagnostics: boolean;
24+
}
2125
export interface FormatterSettings {
2226
SplitAttributesOnFormat: boolean;
2327
}

packages/settings/src/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const defaultSettings: Settings = {
99
logging: { level: "error" },
1010
SAPUI5WebServer: "",
1111
SplitAttributesOnFormat: true,
12+
LimitUniqueIdDiagnostics: false,
1213
};
1314
deepFreezeStrict(defaultSettings);
1415

0 commit comments

Comments
 (0)