Improve extension activation speed
* fix: fix bugs for bug bash * fix: make DigitalTwin graph initiation async
This commit is contained in:
Родитель
3776357c94
Коммит
7703b0789a
|
@ -1735,9 +1735,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"https-proxy-agent": {
|
"https-proxy-agent": {
|
||||||
"version": "2.2.2",
|
"version": "2.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz",
|
||||||
"integrity": "sha512-c8Ndjc9Bkpfx/vCJueCPy0jlP4ccCCSNDp8xwCZzPjKJUm+B+u9WX2x98Qx4n1PiMNTWo3D7KK5ifNV/yJyRzg==",
|
"integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"agent-base": "^4.3.0",
|
"agent-base": "^4.3.0",
|
||||||
|
|
|
@ -143,13 +143,5 @@ export class Utility {
|
||||||
return fs.readJson(filePath, { encoding: Constants.UTF8 });
|
return fs.readJson(filePath, { encoding: Constants.UTF8 });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* get json content from file in synchronous way
|
|
||||||
* @param filePath file path
|
|
||||||
*/
|
|
||||||
public static getJsonContentSync(filePath: string): any {
|
|
||||||
return fs.readJsonSync(filePath, { encoding: Constants.UTF8 });
|
|
||||||
}
|
|
||||||
|
|
||||||
private constructor() {}
|
private constructor() {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,10 +198,8 @@ function initCommand(
|
||||||
}
|
}
|
||||||
|
|
||||||
function initIntelliSense(context: vscode.ExtensionContext): void {
|
function initIntelliSense(context: vscode.ExtensionContext): void {
|
||||||
if (!IntelliSenseUtility.initGraph(context)) {
|
// init DigitalTwin graph
|
||||||
UI.showNotification(MessageType.Warn, UIConstants.INTELLISENSE_NOT_ENABLED_MSG);
|
IntelliSenseUtility.initGraph(context);
|
||||||
return;
|
|
||||||
}
|
|
||||||
// register providers of completionItem and hover
|
// register providers of completionItem and hover
|
||||||
const selector: vscode.DocumentSelector = {
|
const selector: vscode.DocumentSelector = {
|
||||||
language: "json",
|
language: "json",
|
||||||
|
@ -221,9 +219,9 @@ function initIntelliSense(context: vscode.ExtensionContext): void {
|
||||||
Constants.CHANNEL_NAME,
|
Constants.CHANNEL_NAME,
|
||||||
);
|
);
|
||||||
const diagnosticProvider = new DigitalTwinDiagnosticProvider();
|
const diagnosticProvider = new DigitalTwinDiagnosticProvider();
|
||||||
const activateTextEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
|
const activeTextEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
|
||||||
if (activateTextEditor) {
|
if (activeTextEditor) {
|
||||||
diagnosticProvider.updateDiagnostics(activateTextEditor.document, diagnosticCollection);
|
diagnosticProvider.updateDiagnostics(activeTextEditor.document, diagnosticCollection);
|
||||||
}
|
}
|
||||||
context.subscriptions.push(diagnosticCollection);
|
context.subscriptions.push(diagnosticCollection);
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
|
|
|
@ -281,10 +281,7 @@ export class DigitalTwinCompletionItemProvider implements vscode.CompletionItemP
|
||||||
if (propertyNode) {
|
if (propertyNode) {
|
||||||
properties.push(propertyNode);
|
properties.push(propertyNode);
|
||||||
}
|
}
|
||||||
if (required.has(DigitalTwinConstants.CONTEXT)) {
|
// suggest @type property for inline Interface
|
||||||
properties.push({ id: DigitalTwinConstants.CONTEXT });
|
|
||||||
}
|
|
||||||
// suggest @type property for the case that object type is inferred and @type is requried (e.g. inlined Interface)
|
|
||||||
if (required.has(DigitalTwinConstants.TYPE)) {
|
if (required.has(DigitalTwinConstants.TYPE)) {
|
||||||
properties.push({ id: DigitalTwinConstants.TYPE });
|
properties.push({ id: DigitalTwinConstants.TYPE });
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,12 @@ export class DigitalTwinDiagnosticProvider {
|
||||||
DigitalTwinDiagnosticProvider.validateProperties(jsonNode, classNode, problems, exist);
|
DigitalTwinDiagnosticProvider.validateProperties(jsonNode, classNode, problems, exist);
|
||||||
// validate required property
|
// validate required property
|
||||||
if (classNode.constraint && classNode.constraint.required) {
|
if (classNode.constraint && classNode.constraint.required) {
|
||||||
const requiredProperty: string[] = classNode.constraint.required.filter((p) => !exist.has(p));
|
const requiredProperty: string[] = classNode.constraint.required.filter((p) => {
|
||||||
|
// @context is not required for inline Interface
|
||||||
|
const isInterfaceSchem: boolean =
|
||||||
|
p === DigitalTwinConstants.CONTEXT && digitalTwinNode.label === DigitalTwinConstants.SCHEMA;
|
||||||
|
return !exist.has(p) && !isInterfaceSchem;
|
||||||
|
});
|
||||||
if (requiredProperty.length > 0) {
|
if (requiredProperty.length > 0) {
|
||||||
const message: string = [DiagnosticMessage.MissingRequiredProperties, ...requiredProperty].join(
|
const message: string = [DiagnosticMessage.MissingRequiredProperties, ...requiredProperty].join(
|
||||||
Constants.LINE_FEED,
|
Constants.LINE_FEED,
|
||||||
|
@ -425,11 +430,12 @@ export class DigitalTwinDiagnosticProvider {
|
||||||
* @param collection diagnostic collection
|
* @param collection diagnostic collection
|
||||||
*/
|
*/
|
||||||
public updateDiagnostics(document: vscode.TextDocument, collection: vscode.DiagnosticCollection): void {
|
public updateDiagnostics(document: vscode.TextDocument, collection: vscode.DiagnosticCollection): void {
|
||||||
|
// clean diagnostic cache
|
||||||
|
collection.delete(document.uri);
|
||||||
const jsonNode: parser.Node | undefined = IntelliSenseUtility.parseDigitalTwinModel(document.getText());
|
const jsonNode: parser.Node | undefined = IntelliSenseUtility.parseDigitalTwinModel(document.getText());
|
||||||
if (!jsonNode) {
|
if (!jsonNode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
collection.delete(document.uri);
|
|
||||||
const diagnostics: vscode.Diagnostic[] = this.provideDiagnostics(document, jsonNode);
|
const diagnostics: vscode.Diagnostic[] = this.provideDiagnostics(document, jsonNode);
|
||||||
collection.set(document.uri, diagnostics);
|
collection.set(document.uri, diagnostics);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,10 +89,10 @@ export class DigitalTwinGraph {
|
||||||
* get singleton instance of DigitalTwin graph
|
* get singleton instance of DigitalTwin graph
|
||||||
* @param context extension context
|
* @param context extension context
|
||||||
*/
|
*/
|
||||||
public static getInstance(context: vscode.ExtensionContext): DigitalTwinGraph {
|
public static async getInstance(context: vscode.ExtensionContext): Promise<DigitalTwinGraph> {
|
||||||
if (!DigitalTwinGraph.instance) {
|
if (!DigitalTwinGraph.instance) {
|
||||||
DigitalTwinGraph.instance = new DigitalTwinGraph();
|
DigitalTwinGraph.instance = new DigitalTwinGraph();
|
||||||
DigitalTwinGraph.instance.init(context);
|
await DigitalTwinGraph.instance.init(context);
|
||||||
}
|
}
|
||||||
return DigitalTwinGraph.instance;
|
return DigitalTwinGraph.instance;
|
||||||
}
|
}
|
||||||
|
@ -179,15 +179,15 @@ export class DigitalTwinGraph {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read configuration file, return json object
|
* resolve definition
|
||||||
* @param context extension context
|
* @param context extension context
|
||||||
* @param fileName file name
|
* @param fileName file name
|
||||||
*/
|
*/
|
||||||
private static readConfiguration(context: vscode.ExtensionContext, fileName: string): any {
|
private static async resolveDefinition(context: vscode.ExtensionContext, fileName: string): Promise<any> {
|
||||||
const filePath: string = context.asAbsolutePath(
|
const filePath: string = context.asAbsolutePath(
|
||||||
path.join(Constants.RESOURCE_FOLDER, Constants.DEFINITION_FOLDER, fileName),
|
path.join(Constants.RESOURCE_FOLDER, Constants.DEFINITION_FOLDER, fileName),
|
||||||
);
|
);
|
||||||
return Utility.getJsonContentSync(filePath);
|
return await Utility.getJsonContent(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private classNodes: Map<string, ClassNode>;
|
private classNodes: Map<string, ClassNode>;
|
||||||
|
@ -234,15 +234,15 @@ export class DigitalTwinGraph {
|
||||||
* inititalize DigitalTwin graph
|
* inititalize DigitalTwin graph
|
||||||
* @param context extension context
|
* @param context extension context
|
||||||
*/
|
*/
|
||||||
private init(context: vscode.ExtensionContext): void {
|
private async init(context: vscode.ExtensionContext): Promise<void> {
|
||||||
let contextJson;
|
let contextJson;
|
||||||
let constraintJson;
|
let constraintJson;
|
||||||
let graphJson;
|
let graphJson;
|
||||||
// load DigitalTwin definitions by configuration file
|
// load definition file
|
||||||
try {
|
try {
|
||||||
contextJson = DigitalTwinGraph.readConfiguration(context, Constants.CONTEXT_FILE_NAME);
|
contextJson = await DigitalTwinGraph.resolveDefinition(context, Constants.CONTEXT_FILE_NAME);
|
||||||
constraintJson = DigitalTwinGraph.readConfiguration(context, Constants.CONSTRAINT_FILE_NAME);
|
constraintJson = await DigitalTwinGraph.resolveDefinition(context, Constants.CONSTRAINT_FILE_NAME);
|
||||||
graphJson = DigitalTwinGraph.readConfiguration(context, Constants.GRAPH_FILE_NAME);
|
graphJson = await DigitalTwinGraph.resolveDefinition(context, Constants.GRAPH_FILE_NAME);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,8 @@ export interface PropertyPair {
|
||||||
* Utility for IntelliSense
|
* Utility for IntelliSense
|
||||||
*/
|
*/
|
||||||
export class IntelliSenseUtility {
|
export class IntelliSenseUtility {
|
||||||
public static initGraph(context: vscode.ExtensionContext): boolean {
|
public static async initGraph(context: vscode.ExtensionContext): Promise<void> {
|
||||||
IntelliSenseUtility.graph = DigitalTwinGraph.getInstance(context);
|
IntelliSenseUtility.graph = await DigitalTwinGraph.getInstance(context);
|
||||||
return IntelliSenseUtility.graph.initialized();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,6 +65,9 @@ export class IntelliSenseUtility {
|
||||||
* get entry node of DigitalTwin model
|
* get entry node of DigitalTwin model
|
||||||
*/
|
*/
|
||||||
public static getEntryNode(): PropertyNode | undefined {
|
public static getEntryNode(): PropertyNode | undefined {
|
||||||
|
if (!IntelliSenseUtility.graph) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
return IntelliSenseUtility.graph.getPropertyNode(DigitalTwinConstants.ENTRY_NODE);
|
return IntelliSenseUtility.graph.getPropertyNode(DigitalTwinConstants.ENTRY_NODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +76,9 @@ export class IntelliSenseUtility {
|
||||||
* @param name property name
|
* @param name property name
|
||||||
*/
|
*/
|
||||||
public static getPropertyNode(name: string): PropertyNode | undefined {
|
public static getPropertyNode(name: string): PropertyNode | undefined {
|
||||||
|
if (!IntelliSenseUtility.graph) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
return IntelliSenseUtility.graph.getPropertyNode(name);
|
return IntelliSenseUtility.graph.getPropertyNode(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +87,9 @@ export class IntelliSenseUtility {
|
||||||
* @param name class name
|
* @param name class name
|
||||||
*/
|
*/
|
||||||
public static getClasNode(name: string): ClassNode | undefined {
|
public static getClasNode(name: string): ClassNode | undefined {
|
||||||
|
if (!IntelliSenseUtility.graph) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
return IntelliSenseUtility.graph.getClassNode(name);
|
return IntelliSenseUtility.graph.getClassNode(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,10 +226,14 @@ export class ModelRepositoryManager {
|
||||||
throw new BadRequestError("pageSize should be greater than 0");
|
throw new BadRequestError("pageSize should be greater than 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only show output when keyword is defined
|
||||||
|
const showOutput: boolean = keyword ? true : false;
|
||||||
const operation = `Search ${type} by keyword "${keyword}" from ${
|
const operation = `Search ${type} by keyword "${keyword}" from ${
|
||||||
publicRepository ? RepositoryType.Public : RepositoryType.Company
|
publicRepository ? RepositoryType.Public : RepositoryType.Company
|
||||||
}`;
|
}`;
|
||||||
this.outputChannel.start(operation, this.component);
|
if (showOutput) {
|
||||||
|
this.outputChannel.start(operation, this.component);
|
||||||
|
}
|
||||||
|
|
||||||
let result: SearchResult;
|
let result: SearchResult;
|
||||||
try {
|
try {
|
||||||
|
@ -239,7 +243,9 @@ export class ModelRepositoryManager {
|
||||||
throw new ProcessError(operation, error, this.component);
|
throw new ProcessError(operation, error, this.component);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.outputChannel.end(operation, this.component);
|
if (showOutput) {
|
||||||
|
this.outputChannel.end(operation, this.component);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -201,7 +201,13 @@ export class UI {
|
||||||
const items: Array<QuickPickItemWithData<string>> = [];
|
const items: Array<QuickPickItemWithData<string>> = [];
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
files.map(async (f) => {
|
files.map(async (f) => {
|
||||||
const fileInfo: ModelFileInfo | undefined = await Utility.getModelFileInfo(f.path);
|
let fileInfo: ModelFileInfo | undefined;
|
||||||
|
try {
|
||||||
|
fileInfo = await Utility.getModelFileInfo(f.fsPath);
|
||||||
|
} catch {
|
||||||
|
// skip if file is not a valid json
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
if (!type || type === fileInfo.type) {
|
if (!type || type === fileInfo.type) {
|
||||||
items.push({
|
items.push({
|
||||||
|
|
|
@ -21,5 +21,4 @@ export class UIConstants {
|
||||||
"No device model is found in current workspace. Please open the folder that contains models and try again";
|
"No device model is found in current workspace. Please open the folder that contains models and try again";
|
||||||
public static readonly ASK_TO_SAVE_MSG = "The following files contain unsaved changes, do you want to save them?";
|
public static readonly ASK_TO_SAVE_MSG = "The following files contain unsaved changes, do you want to save them?";
|
||||||
public static readonly ASK_TO_OVERWRITE_MSG = "do you want to overwrite it?";
|
public static readonly ASK_TO_OVERWRITE_MSG = "do you want to overwrite it?";
|
||||||
public static readonly INTELLISENSE_NOT_ENABLED_MSG = "Fail to enable intelliSense";
|
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче