mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
adding code
This commit is contained in:
parent
3ea4d66a5b
commit
fffb813460
|
@ -8,12 +8,12 @@ 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, CodeActionKind, CodeAction
|
||||
ProviderResult, TextEdit, Range, Position, Disposable, CompletionItem, CompletionList, CompletionContext, Hover, MarkdownString, FoldingContext, DocumentSymbol, SymbolInformation, l10n, CodeActionContext, CodeAction, Command,
|
||||
} from 'vscode';
|
||||
import {
|
||||
LanguageClientOptions, RequestType, NotificationType, FormattingOptions as LSPFormattingOptions,
|
||||
DidChangeConfigurationNotification, HandleDiagnosticsSignature, ResponseError, DocumentRangeFormattingParams,
|
||||
DocumentRangeFormattingRequest, ProvideCompletionItemsSignature, ProvideHoverSignature, BaseLanguageClient, ProvideFoldingRangeSignature, ProvideDocumentSymbolsSignature, ProvideDocumentColorsSignature
|
||||
DocumentRangeFormattingRequest, ProvideCompletionItemsSignature, ProvideHoverSignature, BaseLanguageClient, ProvideFoldingRangeSignature, ProvideDocumentSymbolsSignature, ProvideDocumentColorsSignature, ProvideCodeActionsSignature
|
||||
} from 'vscode-languageclient';
|
||||
|
||||
|
||||
|
@ -172,7 +172,6 @@ export async function startClient(context: ExtensionContext, newLanguageClient:
|
|||
|
||||
|
||||
toDispose.push(commands.registerCommand('json.sort', async () => {
|
||||
|
||||
if (isClientReady) {
|
||||
const textEditor = window.activeTextEditor;
|
||||
if (textEditor) {
|
||||
|
@ -303,16 +302,15 @@ export async function startClient(context: ExtensionContext, newLanguageClient:
|
|||
}
|
||||
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;
|
||||
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
|
||||
DocumentRangeFormattingRequest, Disposable, ServerCapabilities, TextDocumentSyncKind, TextEdit, DocumentFormattingRequest, TextDocumentIdentifier, FormattingOptions, Diagnostic, 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 } from 'vscode-json-languageservice';
|
||||
import { TextDocument, JSONDocument, JSONSchema, getLanguageService, DocumentLanguageSettings, SchemaConfiguration, ClientCapabilities, Range, Position, SortOptions, CodeAction } from 'vscode-json-languageservice';
|
||||
import { getLanguageModelCache } from './languageModelCache';
|
||||
import { Utils, URI } from 'vscode-uri';
|
||||
|
||||
|
@ -188,7 +188,8 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
|||
documentSelector: null,
|
||||
interFileDependencies: false,
|
||||
workspaceDiagnostics: false
|
||||
}
|
||||
},
|
||||
codeActionProvider: true
|
||||
};
|
||||
|
||||
return { capabilities };
|
||||
|
@ -411,6 +412,7 @@ 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);
|
||||
|
@ -424,6 +426,19 @@ 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');
|
||||
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);
|
||||
});
|
||||
|
||||
function onFormat(textDocument: TextDocumentIdentifier, range: Range | undefined, options: FormattingOptions): TextEdit[] {
|
||||
|
||||
options.keepLines = keepLinesEnabled;
|
||||
|
|
Loading…
Reference in a new issue