Skip to content

Commit f577d8c

Browse files
committed
[json] VS Code suggests another property when a property's casing is not correct. microsoft#881
1 parent 39f9869 commit f577d8c

6 files changed

Lines changed: 1028 additions & 30 deletions

File tree

src/vs/languages/json/common/parser/jsonParser.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ export class ASTNode {
113113
location: { start: this.start, end: this.end },
114114
message: nls.localize('typeArrayMismatchWarning', 'Incorrect type. Expected one of {0}', schema.type.join())
115115
});
116-
} else if (schema.type.length > 0) {
117-
validationResult.typeMatch = true;
118116
}
119117
}
120118
else if (schema.type) {
@@ -123,8 +121,6 @@ export class ASTNode {
123121
location: { start: this.start, end: this.end },
124122
message: nls.localize('typeMismatchWarning', 'Incorrect type. Expected "{0}"', schema.type)
125123
});
126-
} else {
127-
validationResult.typeMatch = true;
128124
}
129125
}
130126
if (Array.isArray(schema.allOf)) {
@@ -212,6 +208,8 @@ export class ASTNode {
212208
location: { start: this.start, end: this.end },
213209
message: nls.localize('enumWarning', 'Value is not an accepted value. Valid values: {0}', JSON.stringify(schema.enum))
214210
});
211+
} else {
212+
validationResult.enumValueMatch = true;
215213
}
216214
}
217215

@@ -717,14 +715,14 @@ export class ValidationResult {
717715

718716
public propertiesMatches: number;
719717
public propertiesValueMatches: number;
720-
public typeMatch: boolean;
718+
public enumValueMatch: boolean;
721719

722720
constructor() {
723721
this.errors = [];
724722
this.warnings = [];
725723
this.propertiesMatches = 0;
726724
this.propertiesValueMatches = 0;
727-
this.typeMatch = false;
725+
this.enumValueMatch = false;
728726
}
729727

730728
public hasErrors():boolean {
@@ -745,7 +743,7 @@ export class ValidationResult {
745743
public mergePropertyMatch(propertyValidationResult: ValidationResult) : void {
746744
this.merge(propertyValidationResult);
747745
this.propertiesMatches++;
748-
if (!propertyValidationResult.hasErrors()) {
746+
if (propertyValidationResult.enumValueMatch || !propertyValidationResult.hasErrors() && propertyValidationResult.propertiesMatches) {
749747
this.propertiesValueMatches++;
750748
}
751749
}
@@ -755,8 +753,8 @@ export class ValidationResult {
755753
if (hasErrors !== other.hasErrors()) {
756754
return hasErrors ? -1 : 1;
757755
}
758-
if (this.typeMatch !== other.typeMatch) {
759-
return other.typeMatch ? -1 : 1;
756+
if (this.enumValueMatch !== other.enumValueMatch) {
757+
return other.enumValueMatch ? -1 : 1;
760758
}
761759
if (this.propertiesValueMatches !== other.propertiesValueMatches) {
762760
return this.propertiesValueMatches - other.propertiesValueMatches;
@@ -781,18 +779,10 @@ export class JSONDocument {
781779
return this.validationResult.errors;
782780
}
783781

784-
public set errors(errors:IError[]) {
785-
this.validationResult.errors = errors;
786-
}
787-
788782
public get warnings():IError[] {
789783
return this.validationResult.warnings;
790784
}
791785

792-
public set warnings(warnings:IError[]) {
793-
this.validationResult.warnings = warnings;
794-
}
795-
796786
public getNodeFromOffset(offset:number):ASTNode {
797787
return this.root && this.root.getNodeFromOffset(offset);
798788
}

0 commit comments

Comments
 (0)