Support for custom field ordering for sort document

Open
#302 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
tooling

Research direction

Start by locating the implementation and entry point for “Sort Document”; the issue does not name files or tests. Clarify whether custom field ordering, settings.json configuration, and sorting arrays by fields are all in scope, then define acceptance tests for configured object-field order and any array-ordering behavior.

Written by the indexing model from the issue text.

Description

You should be able to customize the order of fields when using "Sort Document".
Ideally it should use the order of fields from the JSON schema used by the document. (edit: this probably isn't possible since properties are a dictionary)
This would be very useful when you have large documents with many entries, and you want the order of the fields in the document to be consistent but not strictly sorted alphabetically.
In my case, I have a large array with many entries, and I want the objects' fields to start with "id", then "name", then "description", which is the order they're defined in the JSON schema. However, when using sort document, the order becomes "description", "id", "name", and some other less important fields end up above "id".

Furthermore, a feature that allows you to sort an array by specific fields, such as ordering an objects in an array by their "category" and "date" fields would be great. (edit: it could just use the custom field order). This could probably be seperate from "Sort document", and only apply to the array you're hovering over, something like "Sort array by fields"

There can be a configuration in settings.json which let you define the order of fields, like

fieldOrder = ["category", "id", "name", "description"] // Order fields to have category, id, name, description first
Dominant language
TypeScript
Stars
326
Forks
145
Avg merge
22h 10m
Merged PRs (30d)
9

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/vscode-json-languageservice

All issues in microsoft/vscode-json-languageservice

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.