fix(intellisense): add required label for @type in auto completion
This commit is contained in:
Родитель
7703b0789a
Коммит
f99279bc0f
|
@ -142,7 +142,7 @@ export class DigitalTwinCompletionItemProvider implements vscode.CompletionItemP
|
|||
const dummyNode: PropertyNode = { id: DigitalTwinConstants.TYPE };
|
||||
result.push(
|
||||
DigitalTwinCompletionItemProvider.createCompletionItem(
|
||||
dummyNode.id,
|
||||
`${dummyNode.id} ${DigitalTwinConstants.REQUIRED_PROPERTY_LABEL}`,
|
||||
true,
|
||||
DigitalTwinCompletionItemProvider.getInsertTextForProperty(dummyNode, includeValue, separator),
|
||||
position,
|
||||
|
@ -255,7 +255,7 @@ export class DigitalTwinCompletionItemProvider implements vscode.CompletionItemP
|
|||
* @param required required properties
|
||||
*/
|
||||
private static formatLabel(label: string, required: Set<string>): string {
|
||||
return required.has(label) ? `${label} (required)` : label;
|
||||
return required.has(label) ? `${label} ${DigitalTwinConstants.REQUIRED_PROPERTY_LABEL}` : label;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -445,6 +445,9 @@ export class DigitalTwinCompletionItemProvider implements vscode.CompletionItemP
|
|||
if (!jsonNode) {
|
||||
return undefined;
|
||||
}
|
||||
if (!IntelliSenseUtility.enabled()) {
|
||||
return undefined;
|
||||
}
|
||||
const node: parser.Node | undefined = parser.findNodeAtOffset(jsonNode, document.offsetAt(position));
|
||||
if (!node || node.type !== JsonNodeType.String) {
|
||||
return undefined;
|
||||
|
|
|
@ -50,6 +50,7 @@ export class DigitalTwinConstants {
|
|||
public static readonly UNIT_NODE = "Unit";
|
||||
public static readonly INTERFACE_SCHEMA_NODE = "InterfaceInstance/schema";
|
||||
public static readonly WORD_STOP = ' \t\n\r\v":{[,';
|
||||
public static readonly REQUIRED_PROPERTY_LABEL = "(required)";
|
||||
public static readonly IOT_MODEL_LABEL = "IoTModel";
|
||||
public static readonly CONTEXT_TEMPLATE = "http://azureiot.com/v1/contexts/IoTModel.json";
|
||||
public static readonly CONTEXT_REGEX = new RegExp("^http://azureiot.com/v[0-9]+/contexts/IoTModel.json$");
|
||||
|
|
|
@ -436,6 +436,9 @@ export class DigitalTwinDiagnosticProvider {
|
|||
if (!jsonNode) {
|
||||
return;
|
||||
}
|
||||
if (!IntelliSenseUtility.enabled()) {
|
||||
return;
|
||||
}
|
||||
const diagnostics: vscode.Diagnostic[] = this.provideDiagnostics(document, jsonNode);
|
||||
collection.set(document.uri, diagnostics);
|
||||
}
|
||||
|
|
|
@ -48,6 +48,9 @@ export class DigitalTwinHoverProvider implements vscode.HoverProvider {
|
|||
if (!jsonNode) {
|
||||
return undefined;
|
||||
}
|
||||
if (!IntelliSenseUtility.enabled()) {
|
||||
return undefined;
|
||||
}
|
||||
const node: parser.Node | undefined = parser.findNodeAtOffset(jsonNode, document.offsetAt(position));
|
||||
if (!node || !node.parent) {
|
||||
return undefined;
|
||||
|
|
|
@ -30,10 +30,44 @@ export interface PropertyPair {
|
|||
* Utility for IntelliSense
|
||||
*/
|
||||
export class IntelliSenseUtility {
|
||||
/**
|
||||
* init DigitalTwin graph
|
||||
* @param context extension context
|
||||
*/
|
||||
public static async initGraph(context: vscode.ExtensionContext): Promise<void> {
|
||||
IntelliSenseUtility.graph = await DigitalTwinGraph.getInstance(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if IntelliSense has been enabled
|
||||
*/
|
||||
public static enabled(): boolean {
|
||||
return IntelliSenseUtility.graph && IntelliSenseUtility.graph.initialized();
|
||||
}
|
||||
|
||||
/**
|
||||
* get entry node of DigitalTwin model
|
||||
*/
|
||||
public static getEntryNode(): PropertyNode | undefined {
|
||||
return IntelliSenseUtility.graph.getPropertyNode(DigitalTwinConstants.ENTRY_NODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* get property node of DigitalTwin model by name
|
||||
* @param name property name
|
||||
*/
|
||||
public static getPropertyNode(name: string): PropertyNode | undefined {
|
||||
return IntelliSenseUtility.graph.getPropertyNode(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* get class node of DigitalTwin model by name
|
||||
* @param name class name
|
||||
*/
|
||||
public static getClasNode(name: string): ClassNode | undefined {
|
||||
return IntelliSenseUtility.graph.getClassNode(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the text, return json node if it is DigitalTwin model
|
||||
* @param text text
|
||||
|
@ -61,38 +95,6 @@ export class IntelliSenseUtility {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* get entry node of DigitalTwin model
|
||||
*/
|
||||
public static getEntryNode(): PropertyNode | undefined {
|
||||
if (!IntelliSenseUtility.graph) {
|
||||
return undefined;
|
||||
}
|
||||
return IntelliSenseUtility.graph.getPropertyNode(DigitalTwinConstants.ENTRY_NODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* get property node of DigitalTwin model by name
|
||||
* @param name property name
|
||||
*/
|
||||
public static getPropertyNode(name: string): PropertyNode | undefined {
|
||||
if (!IntelliSenseUtility.graph) {
|
||||
return undefined;
|
||||
}
|
||||
return IntelliSenseUtility.graph.getPropertyNode(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* get class node of DigitalTwin model by name
|
||||
* @param name class name
|
||||
*/
|
||||
public static getClasNode(name: string): ClassNode | undefined {
|
||||
if (!IntelliSenseUtility.graph) {
|
||||
return undefined;
|
||||
}
|
||||
return IntelliSenseUtility.graph.getClassNode(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* parse json node, return property pair
|
||||
* @param node json node
|
||||
|
|
Загрузка…
Ссылка в новой задаче