mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 20:13:32 +01:00
Adding the server and client code to the JSON language features extensions to enable JSONC sorting in VS Code (#174352)
* temporarily changing the funcion onFromat to be able to trigger the sorting on real examples * adding the DocumentSortingRequest * accesssing directly the text edits from the request * added code in order to provide the link between the json sorting capabiliites and vscode * adapting to the new api output of the sort function * instead of using await use then inside of the command that registers * textEditor replaces window.activeTextEditor * adding changes from review * update service * use SortOptions --------- Co-authored-by: Martin Aeschlimann <martinae@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
b4e6254d60
commit
eee87af252
@@ -15,7 +15,7 @@
|
||||
"@vscode/l10n": "^0.0.11",
|
||||
"jsonc-parser": "^3.2.0",
|
||||
"request-light": "^0.7.0",
|
||||
"vscode-json-languageservice": "^5.2.0",
|
||||
"vscode-json-languageservice": "^5.3.0",
|
||||
"vscode-languageserver": "^8.1.0-next.6",
|
||||
"vscode-uri": "^3.0.7"
|
||||
},
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
|
||||
import { runSafe, runSafeAsync } from './utils/runner';
|
||||
import { DiagnosticsSupport, registerDiagnosticsPullSupport, registerDiagnosticsPushSupport } from './utils/validation';
|
||||
import { TextDocument, JSONDocument, JSONSchema, getLanguageService, DocumentLanguageSettings, SchemaConfiguration, ClientCapabilities, Range, Position } from 'vscode-json-languageservice';
|
||||
import { TextDocument, JSONDocument, JSONSchema, getLanguageService, DocumentLanguageSettings, SchemaConfiguration, ClientCapabilities, Range, Position, SortOptions } from 'vscode-json-languageservice';
|
||||
import { getLanguageModelCache } from './languageModelCache';
|
||||
import { Utils, URI } from 'vscode-uri';
|
||||
|
||||
@@ -39,6 +39,20 @@ namespace LanguageStatusRequest {
|
||||
export const type: RequestType<string, JSONLanguageStatus, any> = new RequestType('json/languageStatus');
|
||||
}
|
||||
|
||||
export interface DocumentSortingParams {
|
||||
/**
|
||||
* The uri of the document to sort.
|
||||
*/
|
||||
uri: string;
|
||||
/**
|
||||
* The format options
|
||||
*/
|
||||
options: SortOptions;
|
||||
}
|
||||
|
||||
namespace DocumentSortingRequest {
|
||||
export const type: RequestType<DocumentSortingParams, TextEdit[], any> = new RequestType('json/sort');
|
||||
}
|
||||
|
||||
const workspaceContext = {
|
||||
resolveRelativePath: (relativePath: string, resource: string) => {
|
||||
@@ -112,9 +126,7 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
let jsonColorDecoratorLimit = Number.MAX_VALUE;
|
||||
let jsoncColorDecoratorLimit = Number.MAX_VALUE;
|
||||
|
||||
|
||||
let formatterMaxNumberOfEdits = Number.MAX_VALUE;
|
||||
|
||||
let diagnosticsSupport: DiagnosticsSupport | undefined;
|
||||
|
||||
|
||||
@@ -295,6 +307,16 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
}
|
||||
});
|
||||
|
||||
connection.onRequest(DocumentSortingRequest.type, async params => {
|
||||
const uri = params.uri;
|
||||
const options = params.options;
|
||||
const document = documents.get(uri);
|
||||
if (document) {
|
||||
return languageService.sort(document, options);
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
function updateConfiguration() {
|
||||
const languageSettings = {
|
||||
validate: validateEnabled,
|
||||
@@ -403,6 +425,7 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
});
|
||||
|
||||
function onFormat(textDocument: TextDocumentIdentifier, range: Range | undefined, options: FormattingOptions): TextEdit[] {
|
||||
|
||||
options.keepLines = keepLinesEnabled;
|
||||
const document = documents.get(textDocument.uri);
|
||||
if (document) {
|
||||
|
||||
@@ -27,15 +27,15 @@ request-light@^0.7.0:
|
||||
resolved "https://registry.yarnpkg.com/request-light/-/request-light-0.7.0.tgz#885628bb2f8040c26401ebf258ec51c4ae98ac2a"
|
||||
integrity sha512-lMbBMrDoxgsyO+yB3sDcrDuX85yYt7sS8BfQd11jtbW/z5ZWgLZRcEGLsLoYw7I0WSUGQBs8CC8ScIxkTX1+6Q==
|
||||
|
||||
vscode-json-languageservice@^5.2.0:
|
||||
version "5.2.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-json-languageservice/-/vscode-json-languageservice-5.2.0.tgz#884b7f108be4310e3332167c3ea60ab17f03418c"
|
||||
integrity sha512-q8Rdhu2HEddRxvlhVqwh0cWmKK+OtyMB2xRhtqXEQ7cjb0iZ14madb90iJe9fCHPjoj9CGBrq6QzuOp8OE6XWg==
|
||||
vscode-json-languageservice@^5.3.0:
|
||||
version "5.3.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-json-languageservice/-/vscode-json-languageservice-5.3.0.tgz#b8e8f220f4030af33144182029ac13090d3ceb96"
|
||||
integrity sha512-yVC2WpAaF1swkUBA7EqG3hmSORxI6EpTBGdGgo5DIfJpG5hrk8PzPODAhQd0gVFtTF5j4yFxFD6V1x2XBqagcg==
|
||||
dependencies:
|
||||
"@vscode/l10n" "^0.0.11"
|
||||
jsonc-parser "^3.2.0"
|
||||
vscode-languageserver-textdocument "^1.0.8"
|
||||
vscode-languageserver-types "^3.17.2"
|
||||
vscode-languageserver-types "^3.17.3"
|
||||
vscode-uri "^3.0.7"
|
||||
|
||||
vscode-jsonrpc@8.1.0-next.7:
|
||||
@@ -61,10 +61,10 @@ vscode-languageserver-types@3.17.3-next.3:
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.17.3-next.3.tgz#fc909d37d4200126d74583f2114e53ace27a3e04"
|
||||
integrity sha512-R36Wi5sHoVc/PsAva0QGoEgw+LRCXPDKcdjFfgoVwrRdrFOdYUkvp5G4NvrPUsVT2f2qS/bSs6QiRxyjNkcR9A==
|
||||
|
||||
vscode-languageserver-types@^3.17.2:
|
||||
version "3.17.2"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.17.2.tgz#b2c2e7de405ad3d73a883e91989b850170ffc4f2"
|
||||
integrity sha512-zHhCWatviizPIq9B7Vh9uvrH6x3sK8itC84HkamnBWoDFJtzBf7SWlpLCZUit72b3os45h6RWQNC9xHRDF8dRA==
|
||||
vscode-languageserver-types@^3.17.3:
|
||||
version "3.17.3"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.17.3.tgz#72d05e47b73be93acb84d6e311b5786390f13f64"
|
||||
integrity sha512-SYU4z1dL0PyIMd4Vj8YOqFvHu7Hz/enbWtpfnVbJHU4Nd1YNYx8u0ennumc6h48GQNeOLxmwySmnADouT/AuZA==
|
||||
|
||||
vscode-languageserver@^8.1.0-next.6:
|
||||
version "8.1.0-next.6"
|
||||
|
||||
Reference in New Issue
Block a user