mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
changing to use code action instead of setting
This commit is contained in:
@@ -8,7 +8,7 @@ export type JSONLanguageStatus = { schemas: string[] };
|
||||
import {
|
||||
workspace, window, languages, commands, ExtensionContext, extensions, Uri, ColorInformation,
|
||||
Diagnostic, StatusBarAlignment, TextEditor, TextDocument, FormattingOptions, CancellationToken, FoldingRange,
|
||||
ProviderResult, TextEdit, Range, Position, Disposable, CompletionItem, CompletionList, CompletionContext, Hover, MarkdownString, FoldingContext, DocumentSymbol, SymbolInformation, l10n, TextEditorOptions
|
||||
ProviderResult, TextEdit, Range, Position, Disposable, CompletionItem, CompletionList, CompletionContext, Hover, MarkdownString, FoldingContext, DocumentSymbol, SymbolInformation, l10n, CodeActionKind, CodeAction
|
||||
} from 'vscode';
|
||||
import {
|
||||
LanguageClientOptions, RequestType, NotificationType, FormattingOptions as LSPFormattingOptions,
|
||||
@@ -102,7 +102,6 @@ export type JSONSchemaSettings = {
|
||||
export namespace SettingIds {
|
||||
export const enableFormatter = 'json.format.enable';
|
||||
export const enableKeepLines = 'json.format.keepLines';
|
||||
export const enableSortOnSave = 'json.sortOnSave.enable';
|
||||
export const enableValidation = 'json.validate.enable';
|
||||
export const enableSchemaDownload = 'json.schemaDownload.enable';
|
||||
export const maxItemsComputed = 'json.maxItemsComputed';
|
||||
@@ -171,15 +170,6 @@ export async function startClient(context: ExtensionContext, newLanguageClient:
|
||||
window.showInformationMessage(l10n.t('JSON schema cache cleared.'));
|
||||
}));
|
||||
|
||||
toDispose.push(workspace.onWillSaveTextDocument(event => {
|
||||
const sortOnSave = workspace.getConfiguration().get<boolean>(SettingIds.enableSortOnSave);
|
||||
const document = event.document;
|
||||
if (sortOnSave && (document.languageId === 'json' || document.languageId === 'jsonc')) {
|
||||
const documentOptions = getOptionsForDocument(document);
|
||||
const textEditsPromise = getSortTextEdits(document, documentOptions?.tabSize, documentOptions?.insertSpaces);
|
||||
event.waitUntil(textEditsPromise);
|
||||
}
|
||||
}));
|
||||
|
||||
toDispose.push(commands.registerCommand('json.sort', async () => {
|
||||
|
||||
@@ -312,6 +302,17 @@ export async function startClient(context: ExtensionContext, newLanguageClient:
|
||||
return r.then(checkLimit);
|
||||
}
|
||||
return checkLimit(r);
|
||||
},
|
||||
provideCodeActions(doc) {
|
||||
console.log('doc : ', doc);
|
||||
console.log('inside of provideCodeActions');
|
||||
const codeActions: CodeAction[] = [];
|
||||
const sortCodeAction = new CodeAction('Sort JSON', CodeActionKind.Source);
|
||||
sortCodeAction.command = {
|
||||
command: 'json.sort',
|
||||
title: 'Sort JSON'
|
||||
};
|
||||
return codeActions;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -643,12 +644,3 @@ function updateMarkdownString(h: MarkdownString): MarkdownString {
|
||||
function isSchemaResolveError(d: Diagnostic) {
|
||||
return d.code === /* SchemaResolveError */ 0x300;
|
||||
}
|
||||
|
||||
function getOptionsForDocument(document: TextDocument): TextEditorOptions | undefined {
|
||||
for (const editor of window.visibleTextEditors) {
|
||||
if (editor.document.uri.toString() === document.uri.toString()) {
|
||||
return editor.options;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -91,12 +91,6 @@
|
||||
"default": false,
|
||||
"description": "%json.format.keepLines.desc%"
|
||||
},
|
||||
"json.sortOnSave.enable": {
|
||||
"type": "boolean",
|
||||
"scope": "window",
|
||||
"default": false,
|
||||
"description": "%json.sortOnSave.enable.desc%"
|
||||
},
|
||||
"json.trace.server": {
|
||||
"type": "string",
|
||||
"scope": "window",
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
"json.schemas.schema.desc": "The schema definition for the given URL. The schema only needs to be provided to avoid accesses to the schema URL.",
|
||||
"json.format.enable.desc": "Enable/disable default JSON formatter",
|
||||
"json.format.keepLines.desc" : "Keep all existing new lines when formatting.",
|
||||
"json.sortOnSave.enable.desc": "Enable/disable default sorting on save",
|
||||
"json.validate.enable.desc": "Enable/disable JSON validation.",
|
||||
"json.tracing.desc": "Traces the communication between VS Code and the JSON language server.",
|
||||
"json.colorDecorators.enable.desc": "Enables or disables color decorators",
|
||||
|
||||
Reference in New Issue
Block a user