redhat-developer / redhat-developer/yaml-language-server
support propertyOrder for completions
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.5k
- Forks
- 352
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 11
Description
Is your enhancement related to a problem? Please describe.
JSONSchema supports propertyOrder, which acts as an aid for UIs to perform completions in the order as was intended by the developer. This is incredibly useful for users as it makes creating a YAML from scratch "look" more understandable.
Describe the solution you would like
yamlcompletions that follow the propertyOrder directive in JSON schema
Describe alternatives you have considered
Patch proposed
Additional context
The following would provide this functionality:
diff --git a/src/languageservice/jsonSchema.ts b/src/languageservice/jsonSchema.ts
index e8b6f90..1688a0b 100644
--- a/src/languageservice/jsonSchema.ts
+++ b/src/languageservice/jsonSchema.ts
@@ -19,6 +19,7 @@ export interface JSONSchema {
definitions?: { [name: string]: JSONSchema };
description?: string;
properties?: JSONSchemaMap;
+ propertyOrder?: string[];
patternProperties?: JSONSchemaMap;
additionalProperties?: boolean | JSONSchemaRef;
minProperties?: number;
diff --git a/src/languageservice/services/yamlCompletion.ts b/src/languageservice/services/yamlCompletion.ts
index 701c79f..c216f88 100644
--- a/src/languageservice/services/yamlCompletion.ts
+++ b/src/languageservice/services/yamlCompletion.ts
@@ -298,7 +298,6 @@ export class YamlCompletion {
}
}
}
-
this.addPropertyCompletions(schema, currentDoc, node, '', collector, textBuffer, overwriteRange);
if (!schema && currentWord.length > 0 && document.getText().charAt(offset - currentWord.length - 1) !== '"') {
@@ -655,7 +654,8 @@ export class YamlCompletion {
return { insertText, insertIndex };
}
- Object.keys(schema.properties).forEach((key: string) => {
+ const iterator = schema.propertyOrder !== undefined ? schema.propertyOrder : Object.keys(schema.properties);
+ iterator.forEach((key: string) => {
const propertySchema = schema.properties[key] as JSONSchema;
let type = Array.isArray(propertySchema.type) ? propertySchema.type[0] : propertySchema.type;
if (!type) {
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/languageservice/jsonSchema.ts to inspect the JSONSchema definition, then follow addPropertyCompletions in src/languageservice/services/yamlCompletion.ts. Confirm that YAML completions use propertyOrder when provided and retain the existing property ordering behavior otherwise.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100