Skip to content

Commit

Permalink
Merge pull request #409 from iljapostnovs/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
iljapostnovs authored May 24, 2024
2 parents 5bc7eb5 + 61f651e commit bbde926
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.19.0 (24-05-2024)

- New preference entry added: `ui5.plugin.parsingDelay`. It serves as a delay for parsing, which can be handy for large projects in order to gain better performance.

## 1.18.1 (15-04-2024)

- [UI5 Linter](https://github.com/iljapostnovs/ui5plugin-linter) updated to v1.15.1
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ui5plugin",
"displayName": "SAPUI5 Extension",
"description": "Extension for working with UI5 projects",
"version": "1.18.1",
"version": "1.19.0",
"publisher": "iljapostnovs",
"license": "Apache-2.0",
"author": "Ilja Postnovs <ilja.postnovs@gmail.com>",
Expand Down Expand Up @@ -418,6 +418,11 @@
}
},
"markdownDescription": "Data for `ui5plugin.bulkExportToi18n` command. Contains data about which proprties should be exported to i18n."
},
"ui5.plugin.parsingDelay": {
"type": "number",
"default": 500,
"markdownDescription": "Delay for parsing JS/TS files. Increase it for large projects to gain in performance."
}
}
},
Expand Down Expand Up @@ -554,4 +559,4 @@
"publisherId": "ec65c605-dbb1-4486-bd8a-a99b8c9e30da",
"isPreReleaseVersion": false
}
}
}
24 changes: 14 additions & 10 deletions src/classes/registrators/DiagnosticsRegistrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { JSLinter } from "../ui5linter/js/JSLinter";
import { PropertiesLinter } from "../ui5linter/properties/PropertiesLinter";
import { TSLinter } from "../ui5linter/ts/TSLinter";
import { XMLLinter } from "../ui5linter/xml/XMLLinter";
import EventBus from "../utils/EventBus";

let xmlDiagnosticCollection: vscode.DiagnosticCollection;
let jsDiagnosticCollection: vscode.DiagnosticCollection;
Expand Down Expand Up @@ -44,14 +45,17 @@ export class DiagnosticsRegistrator {
}
});

const textDocumentChange = vscode.workspace.onDidChangeTextDocument(event => {
if (event.contentChanges.length > 0) {
DiagnosticsRegistrator.updateDiagnosticCollection(event.document);
}
// const textDocumentChange = vscode.workspace.onDidChangeTextDocument(event => {
// if (event.contentChanges.length > 0) {
// DiagnosticsRegistrator.updateDiagnosticCollection(event.document);
// }
// });
EventBus.subscribeCodeUpdated((document: vscode.TextDocument) => {
DiagnosticsRegistrator.updateDiagnosticCollection(document);
});

UI5Plugin.getInstance().addDisposable(changeActiveTextEditor);
UI5Plugin.getInstance().addDisposable(textDocumentChange);
// UI5Plugin.getInstance().addDisposable(textDocumentChange);
}

private static async _updatePropertiesDiagnostics(
Expand Down Expand Up @@ -92,7 +96,7 @@ export class DiagnosticsRegistrator {
}
}

static updateDiagnosticCollection(document: vscode.TextDocument, bForce = false) {
static updateDiagnosticCollection(document: vscode.TextDocument, refreshCode = false) {
const fileName = document.fileName;
const parser = ParserPool.getParserForFile(fileName);
if (!parser) {
Expand All @@ -107,14 +111,14 @@ export class DiagnosticsRegistrator {
this._updateXMLDiagnostics(document, xmlDiagnosticCollection);
} else if (fileName.endsWith(".js")) {
const className = parser.fileReader.getClassNameFromPath(fileName);
if (className) {
parser.classFactory.setNewCodeForClass(className, document.getText(), bForce);
if (className && refreshCode) {
parser.classFactory.setNewCodeForClass(className, document.getText(), true);
}
this._updateJSDiagnostics(document, jsDiagnosticCollection);
} else if (fileName.endsWith(".ts")) {
const className = parser.fileReader.getClassNameFromPath(fileName);
if (className) {
parser.classFactory.setNewCodeForClass(className, document.getText(), bForce);
if (className && refreshCode) {
parser.classFactory.setNewCodeForClass(className, document.getText(), true);
}
this._updateTSDiagnostics(document, tsDiagnosticCollection);
} else if (fileName.endsWith(".properties")) {
Expand Down
14 changes: 14 additions & 0 deletions src/classes/utils/EventBus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TextDocument } from "vscode";

export default class EventBus {
private static readonly _subscriptions: Record<string, ((document: TextDocument) => void)[]> = {
CodeUpdated: []
};
static subscribeCodeUpdated(handler: (document: TextDocument) => void) {
this._subscriptions.CodeUpdated.push(handler);
}

static fireCodeUpdated(document: TextDocument) {
this._subscriptions.CodeUpdated.forEach(handler => handler(document));
}
}
61 changes: 42 additions & 19 deletions src/classes/utils/FileWatcherMediator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { IFileChanges, IFileRenameData } from "../filerenaming/handlers/abstract
import { DiagnosticsRegistrator } from "../registrators/DiagnosticsRegistrator";
import { TemplateGeneratorFactory } from "../templateinserters/filetemplates/factory/TemplateGeneratorFactory";
import { ClearCacheCommand } from "../vscommands/ClearCacheCommand";
import EventBus from "./EventBus";
import { VSCodeFileReader } from "./VSCodeFileReader";
import path = require("path");

const workspace = vscode.workspace;

export class FileWatcherMediator {
private static readonly _parsingTimeout: Record<string, NodeJS.Timeout> = {};
private async _onChange(
uri: vscode.Uri,
document?: vscode.TextDocument,
Expand Down Expand Up @@ -62,36 +64,57 @@ export class FileWatcherMediator {
if (document.fileName.endsWith(".js") || document.fileName.endsWith(".ts")) {
const currentClassNameDotNotation = parser.fileReader.getClassNameFromPath(document.fileName);
if (currentClassNameDotNotation) {
if (document.fileName.endsWith(".ts") && parser instanceof UI5TSParser) {
// const textChanges: ts.TextChange[] | undefined = contentChanges?.map(contentChange => {
// return {
// newText: contentChange.text,
// span: { length: contentChange.rangeLength, start: contentChange.rangeOffset }
// };
// });
parser.classFactory.setNewCodeForClass(
currentClassNameDotNotation,
document.getText(),
force,
undefined,
undefined,
true,
undefined
// textChanges
);
} else {
parser.classFactory.setNewCodeForClass(currentClassNameDotNotation, document.getText(), force);
if (FileWatcherMediator._parsingTimeout[document.fileName]) {
clearTimeout(FileWatcherMediator._parsingTimeout[document.fileName]);
}

FileWatcherMediator._parsingTimeout[document.fileName] = setTimeout(() => {
if (!document) {
return;
}
if (document.fileName.endsWith(".ts") && parser instanceof UI5TSParser) {
// const textChanges: ts.TextChange[] | undefined = contentChanges?.map(contentChange => {
// return {
// newText: contentChange.text,
// span: { length: contentChange.rangeLength, start: contentChange.rangeOffset }
// };
// });
parser.classFactory.setNewCodeForClass(
currentClassNameDotNotation,
document.getText(),
force,
undefined,
undefined,
true,
undefined
// textChanges
);
} else {
parser.classFactory.setNewCodeForClass(currentClassNameDotNotation, document.getText(), force);
}

EventBus.fireCodeUpdated(document);

delete FileWatcherMediator._parsingTimeout[document.fileName];
}, vscode.workspace.getConfiguration("ui5.plugin").get<number>("parsingDelay"));
}
} else if (document.fileName.endsWith(".view.xml")) {
const viewContent = document.getText();
parser.fileReader.setNewViewContentToCache(viewContent, toNative(document.uri.fsPath), true);

EventBus.fireCodeUpdated(document);
} else if (document.fileName.endsWith(".fragment.xml")) {
parser.fileReader.setNewFragmentContentToCache(document.getText(), toNative(document.fileName), true);

EventBus.fireCodeUpdated(document);
} else if (document.fileName.endsWith("18n.properties")) {
parser.resourceModelData.updateCache(new TextDocumentAdapter(document));

EventBus.fireCodeUpdated(document);
} else if (document.fileName.endsWith("manifest.json")) {
parser.fileReader.rereadAllManifests();

EventBus.fireCodeUpdated(document);
}

this._updateDiagnosticsIfNecessary(document);
Expand Down

0 comments on commit bbde926

Please sign in to comment.