unsure how to register the provider
parent
fffb813460
commit
06fdc0a633
|
@ -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, CodeActionContext, CodeAction, Command,
|
||||
ProviderResult, TextEdit, Range, Position, Disposable, CompletionItem, CompletionList, CompletionContext, Hover, MarkdownString, FoldingContext, DocumentSymbol, SymbolInformation, l10n, CodeActionContext, CodeAction, Command, CodeActionProvider, Selection, CodeActionKind,
|
||||
} from 'vscode';
|
||||
import {
|
||||
LanguageClientOptions, RequestType, NotificationType, FormattingOptions as LSPFormattingOptions,
|
||||
|
@ -172,6 +172,7 @@ export async function startClient(context: ExtensionContext, newLanguageClient:
|
|||
|
||||
|
||||
toDispose.push(commands.registerCommand('json.sort', async () => {
|
||||
|
||||
if (isClientReady) {
|
||||
const textEditor = window.activeTextEditor;
|
||||
if (textEditor) {
|
||||
|
@ -189,6 +190,35 @@ export async function startClient(context: ExtensionContext, newLanguageClient:
|
|||
}
|
||||
}));
|
||||
|
||||
class JSONCodeActionProvider implements CodeActionProvider {
|
||||
|
||||
provideCodeActions(document: TextDocument, range: Range | Selection, context: CodeActionContext, token: CancellationToken): ProviderResult<(CodeAction | Command)[]> {
|
||||
console.log('inside of provide code actions');
|
||||
const codeActions: CodeAction[] = [];
|
||||
const sortCodeAction = new CodeAction('Sort JSON', CodeActionKind.Source);
|
||||
sortCodeAction.command = {
|
||||
command: 'json.sort',
|
||||
title: 'Sort JSON'
|
||||
};
|
||||
return codeActions;
|
||||
}
|
||||
}
|
||||
|
||||
languages.registerCodeActionsProvider('*', new JSONCodeActionProvider());
|
||||
|
||||
// connection.onCodeAction((_codeActionParams, token) => {
|
||||
// return runSafe(runtime, () => {
|
||||
// console.log('Inside of on code action');
|
||||
// const codeActions: CodeAction[] = [];
|
||||
// const sortCodeAction = CodeAction.create('Sort JSON', CodeActionKind.Source);
|
||||
// sortCodeAction.command = {
|
||||
// command: 'json.sort',
|
||||
// title: 'Sort JSON'
|
||||
// };
|
||||
// return codeActions;
|
||||
// }, [], `Error while retrieving code actions`, token);
|
||||
// });
|
||||
|
||||
// Options to control the language client
|
||||
const clientOptions: LanguageClientOptions = {
|
||||
// Register the server for json documents
|
||||
|
@ -302,16 +332,16 @@ export async function startClient(context: ExtensionContext, newLanguageClient:
|
|||
}
|
||||
return checkLimit(r);
|
||||
},
|
||||
provideCodeActions(document: TextDocument, range: Range, context: CodeActionContext, token: CancellationToken, next: ProvideCodeActionsSignature) {
|
||||
console.log('inside of provide code actions');
|
||||
console.log('next : ', next);
|
||||
const r = next(document, range, context, token);
|
||||
console.log('r : ', r);
|
||||
if (isThenable<(Command | CodeAction)[] | null | undefined>(r)) {
|
||||
return r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
// provideCodeActions(document: TextDocument, range: Range, context: CodeActionContext, token: CancellationToken, next: ProvideCodeActionsSignature) {
|
||||
// console.log('inside of provide code actions');
|
||||
// console.log('next : ', next);
|
||||
// const r = next(document, range, context, token);
|
||||
// console.log('r : ', r);
|
||||
// if (isThenable<(Command | CodeAction)[] | null | undefined>(r)) {
|
||||
// return r;
|
||||
// }
|
||||
// return r;
|
||||
// }
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
import {
|
||||
Connection,
|
||||
TextDocuments, InitializeParams, InitializeResult, NotificationType, RequestType,
|
||||
DocumentRangeFormattingRequest, Disposable, ServerCapabilities, TextDocumentSyncKind, TextEdit, DocumentFormattingRequest, TextDocumentIdentifier, FormattingOptions, Diagnostic, CodeActionKind
|
||||
DocumentRangeFormattingRequest, Disposable, ServerCapabilities, TextDocumentSyncKind, TextEdit, DocumentFormattingRequest, TextDocumentIdentifier, FormattingOptions, Diagnostic, CodeAction, CodeActionKind
|
||||
} from 'vscode-languageserver';
|
||||
|
||||
import { runSafe, runSafeAsync } from './utils/runner';
|
||||
import { DiagnosticsSupport, registerDiagnosticsPullSupport, registerDiagnosticsPushSupport } from './utils/validation';
|
||||
import { TextDocument, JSONDocument, JSONSchema, getLanguageService, DocumentLanguageSettings, SchemaConfiguration, ClientCapabilities, Range, Position, SortOptions, CodeAction } 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';
|
||||
|
||||
|
@ -412,7 +412,6 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
|||
|
||||
connection.onDocumentSymbol((documentSymbolParams, token) => {
|
||||
return runSafe(runtime, () => {
|
||||
console.log('inside of on document symbol');
|
||||
const document = documents.get(documentSymbolParams.textDocument.uri);
|
||||
if (document) {
|
||||
const jsonDocument = getJSONDocument(document);
|
||||
|
@ -426,6 +425,7 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
|||
}, [], `Error while computing document symbols for ${documentSymbolParams.textDocument.uri}`, token);
|
||||
});
|
||||
|
||||
//
|
||||
connection.onCodeAction((_codeActionParams, token) => {
|
||||
return runSafe(runtime, () => {
|
||||
console.log('Inside of on code action');
|
||||
|
@ -439,6 +439,11 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
|||
}, [], `Error while retrieving code actions`, token);
|
||||
});
|
||||
|
||||
connection.onCodeActionResolve(async (codeAction, token) => {
|
||||
return codeAction;
|
||||
});
|
||||
//
|
||||
|
||||
function onFormat(textDocument: TextDocumentIdentifier, range: Range | undefined, options: FormattingOptions): TextEdit[] {
|
||||
|
||||
options.keepLines = keepLinesEnabled;
|
||||
|
|
Loading…
Reference in New Issue