blob: ffe914ebd994b6274085a7e3fb86df4b231bd287 [file] [log] [blame]
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// This file has been automatically generated. Please do not edit it manually.
// To regenerate the file, use the script
// "pkg/analysis_server/tool/lsp_spec/generate_all.dart".
import 'dart:core' hide deprecated;
import 'dart:core' as core show deprecated;
import 'dart:convert' show JsonEncoder;
import 'package:analysis_server/lsp_protocol/protocol_custom_generated.dart';
import 'package:analysis_server/lsp_protocol/protocol_special.dart';
import 'package:analysis_server/src/lsp/json_parsing.dart';
import 'package:analysis_server/src/protocol/protocol_internal.dart';
const jsonEncoder = JsonEncoder.withIndent(' ');
/// Result for a request to resolve the incoming calls for a given
/// `CallHierarchyItem`.
///
/// @since 3.16.0
typedef CallHierarchyIncomingCallsResult = List<CallHierarchyIncomingCall>?;
/// Result for a request to resolve the outgoing calls for a given
/// `CallHierarchyItem`.
///
/// @since 3.16.0
typedef CallHierarchyOutgoingCallsResult = List<CallHierarchyOutgoingCall>?;
/// An identifier to refer to a change annotation stored with a workspace edit.
typedef ChangeAnnotationIdentifier = String;
/// The declaration of a symbol representation as one or many locations.
typedef Declaration = Either2<List<Location>, Location>;
/// Information about where a symbol is declared.
///
/// Provides additional metadata over normal location declarations, including
/// the range of the declaring symbol.
///
/// Servers should prefer returning `DeclarationLink` over `Declaration` if
/// supported by the client.
typedef DeclarationLink = LocationLink;
/// The definition of a symbol represented as one or many locations. For most
/// programming languages there is only one location at which a symbol is
/// defined.
///
/// Servers should prefer returning `DefinitionLink` over `Definition` if
/// supported by the client.
typedef Definition = Either2<List<Location>, Location>;
/// Information about where a symbol is defined.
///
/// Provides additional metadata over normal location definitions, including the
/// range of the defining symbol
typedef DefinitionLink = LocationLink;
/// The result of a document diagnostic pull request. A report can either be a
/// full report containing all diagnostics for the requested document or an
/// unchanged report indicating that nothing has changed in terms of diagnostics
/// in comparison to the last pull request.
///
/// @since 3.17.0
typedef DocumentDiagnosticReport = Either2<RelatedFullDocumentDiagnosticReport,
RelatedUnchangedDocumentDiagnosticReport>;
/// A document filter describes a top level text document or a notebook cell
/// document.
///
/// @since 3.17.0 - proposed support for NotebookCellTextDocumentFilter.
typedef DocumentFilter
= Either2<NotebookCellTextDocumentFilter, TextDocumentFilter>;
/// A document selector is the combination of one or many document filters.
///
/// @sample `let sel:DocumentSelector = [{ language: 'typescript' }, { language:
/// 'json', pattern: '**∕tsconfig.json' }]`;
///
/// The use of a string as a document filter is deprecated @since 3.16.0.
typedef DocumentSelector = List<Either2<TextDocumentFilterWithScheme, String>>;
/// The glob pattern. Either a string pattern or a relative pattern.
///
/// @since 3.17.0
typedef GlobPattern = Either2<LspPattern, RelativePattern>;
/// Inline value information can be provided by different means:
/// - directly as a text value (class InlineValueText).
/// - as a name to use for a variable lookup (class InlineValueVariableLookup)
/// - as an evaluatable expression (class InlineValueEvaluatableExpression) The
/// InlineValue types combines all inline value types into one type.
///
/// @since 3.17.0
typedef InlineValue = Either3<InlineValueEvaluatableExpression, InlineValueText,
InlineValueVariableLookup>;
/// LSP arrays.
/// @since 3.17.0
typedef LSPArray = List<LSPAny>;
/// The glob pattern to watch relative to the base path. Glob patterns can have
/// the following syntax:
/// - `*` to match one or more characters in a path segment
/// - `?` to match on one character in a path segment
/// - `**` to match any number of path segments, including none
/// - `{}` to group conditions (e.g. `**​/*.{ts,js}` matches all TypeScript and
/// JavaScript files)
/// - `[]` to declare a range of characters to match in a path segment (e.g.,
/// `example.[0-9]` to match on `example.0`, `example.1`, …)
/// - `[!...]` to negate a range of characters to match in a path segment (e.g.,
/// `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`)
///
/// @since 3.17.0
typedef LspPattern = String;
/// A tagging type for string properties that are actually URIs
///
/// @since 3.16.0
typedef LspUri = String;
/// A notebook document filter denotes a notebook document by different
/// properties. The properties will be match against the notebook's URI (same as
/// with documents)
///
/// @since 3.17.0
typedef NotebookDocumentFilter = Either3<NotebookDocumentFilter1,
NotebookDocumentFilter2, NotebookDocumentFilter3>;
typedef PrepareRenameResult
= Either3<PlaceholderAndRange, PrepareRenameResult2, Range>;
typedef ProgressToken = Either2<int, String>;
/// Result for a request to provide commands for the given text document and
/// range.
typedef TextDocumentCodeActionResult = List<Either2<CodeAction, Command>>?;
/// Result for a request to provide code lens for the given text document.
typedef TextDocumentCodeLensResult = List<CodeLens>?;
/// Result for request to request completion at a given text document position.
/// The request's parameter is of type TextDocumentPosition the response is of
/// type [CompletionItem[]](#CompletionItem) or CompletionList or a Thenable
/// that resolves to such.
///
/// The request can delay the computation of the `detail` and `documentation`
/// properties to the `completionItem/resolve` request. However, properties that
/// are needed for the initial sorting and filtering, like `sortText`,
/// `filterText`, `insertText`, and `textEdit`, must not be changed during
/// resolve.
typedef TextDocumentCompletionResult
= Either2<CompletionList, List<CompletionItem>>?;
/// An event describing a change to a text document. If only a text is provided
/// it is considered to be the full content of the document.
typedef TextDocumentContentChangeEvent
= Either2<TextDocumentContentChangeEvent1, TextDocumentContentChangeEvent2>;
/// Result for a request to resolve the type definition locations of a symbol at
/// a given text document position. The request's parameter is of type
/// TextDocumentPositionParams the response is of type Declaration or a typed
/// array of DeclarationLink or a Thenable that resolves to such.
typedef TextDocumentDeclarationResult
= Either2<Declaration, List<DeclarationLink>>?;
/// Result for a request to resolve the definition location of a symbol at a
/// given text document position. The request's parameter is of type
/// TextDocumentPosition the response is of either type Definition or a typed
/// array of DefinitionLink or a Thenable that resolves to such.
typedef TextDocumentDefinitionResult
= Either2<Definition, List<DefinitionLink>>?;
/// Result for request to resolve a DocumentHighlight for a given text document
/// position. The request's parameter is of type TextDocumentPosition the
/// request response is of type [DocumentHighlight[]] (#DocumentHighlight) or a
/// Thenable that resolves to such.
typedef TextDocumentDocumentHighlightResult = List<DocumentHighlight>?;
/// Result for a request to provide document links
typedef TextDocumentDocumentLinkResult = List<DocumentLink>?;
/// Result for a request to list all symbols found in a given text document. The
/// request's parameter is of type TextDocumentIdentifier the response is of
/// type [SymbolInformation[]](#SymbolInformation) or a Thenable that resolves
/// to such.
typedef TextDocumentDocumentSymbolResult
= Either2<List<DocumentSymbol>, List<SymbolInformation>>?;
/// A document filter denotes a document by different properties like the
/// language, the scheme of its resource, or a glob-pattern that is applied to
/// the path.
///
/// Glob patterns can have the following syntax:
/// - `*` to match one or more characters in a path segment
/// - `?` to match on one character in a path segment
/// - `**` to match any number of path segments, including none
/// - `{}` to group sub patterns into an OR expression. (e.g. `**​/*.{ts,js}`
/// matches all TypeScript and JavaScript files)
/// - `[]` to declare a range of characters to match in a path segment (e.g.,
/// `example.[0-9]` to match on `example.0`, `example.1`, …)
/// - `[!...]` to negate a range of characters to match in a path segment (e.g.,
/// `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`)
///
/// @sample A language filter that applies to typescript files on disk: `{
/// language: 'typescript', scheme: 'file' }`
/// @sample A language filter that applies to all package.json paths: `{
/// language: 'json', pattern: '**package.json' }`
///
/// @since 3.17.0
typedef TextDocumentFilter = Either3<TextDocumentFilter1,
TextDocumentFilterWithScheme, TextDocumentFilter3>;
/// Result for a request to provide folding ranges in a document. The request's
/// parameter is of type FoldingRangeParams, the response is of type
/// FoldingRangeList or a Thenable that resolves to such.
typedef TextDocumentFoldingRangeResult = List<FoldingRange>?;
/// Result for a request to to format a whole document.
typedef TextDocumentFormattingResult = List<TextEdit>?;
/// Result for request to request hover information at a given text document
/// position. The request's parameter is of type TextDocumentPosition the
/// response is of type Hover or a Thenable that resolves to such.
typedef TextDocumentHoverResult = Hover?;
/// Result for a request to resolve the implementation locations of a symbol at
/// a given text document position. The request's parameter is of type
/// TextDocumentPositionParams the response is of type Definition or a Thenable
/// that resolves to such.
typedef TextDocumentImplementationResult
= Either2<Definition, List<DefinitionLink>>?;
/// Result for a request to provide inlay hints in a document. The request's
/// parameter is of type InlayHintsParams, the response is of type
/// [InlayHint[]](#InlayHint[]) or a Thenable that resolves to such.
///
/// @since 3.17.0
typedef TextDocumentInlayHintResult = List<InlayHint>?;
/// Result for a request to provide inline values in a document. The request's
/// parameter is of type InlineValueParams, the response is of type
/// [InlineValue[]](#InlineValue[]) or a Thenable that resolves to such.
///
/// @since 3.17.0
typedef TextDocumentInlineValueResult = List<InlineValue>?;
/// Result for a request to provide ranges that can be edited together.
///
/// @since 3.16.0
typedef TextDocumentLinkedEditingRangeResult = LinkedEditingRanges?;
/// Result for a request to get the moniker of a symbol at a given text document
/// position. The request parameter is of type TextDocumentPositionParams. The
/// response is of type [Moniker[]](#Moniker[]) or `null`.
typedef TextDocumentMonikerResult = List<Moniker>?;
/// Result for a request to format a document on type.
typedef TextDocumentOnTypeFormattingResult = List<TextEdit>?;
/// Result for a request to result a `CallHierarchyItem` in a document at a
/// given position. Can be used as an input to an incoming or outgoing call
/// hierarchy.
///
/// @since 3.16.0
typedef TextDocumentPrepareCallHierarchyResult = List<CallHierarchyItem>?;
/// Result for a request to test and perform the setup necessary for a rename.
///
/// @since 3.16 - support for default behavior
typedef TextDocumentPrepareRenameResult = PrepareRenameResult?;
/// Result for a request to result a `TypeHierarchyItem` in a document at a
/// given position. Can be used as an input to a subtypes or supertypes type
/// hierarchy.
///
/// @since 3.17.0
typedef TextDocumentPrepareTypeHierarchyResult = List<TypeHierarchyItem>?;
/// Result for a request to to format a range in a document.
typedef TextDocumentRangeFormattingResult = List<TextEdit>?;
/// Result for a request to resolve project-wide references for the symbol
/// denoted by the given text document position. The request's parameter is of
/// type ReferenceParams the response is of type [Location[]](#Location) or a
/// Thenable that resolves to such.
typedef TextDocumentReferencesResult = List<Location>?;
/// Result for a request to rename a symbol.
typedef TextDocumentRenameResult = WorkspaceEdit?;
/// Result for a request to provide selection ranges in a document. The
/// request's parameter is of type SelectionRangeParams, the response is of type
/// [SelectionRange[]](#SelectionRange[]) or a Thenable that resolves to such.
typedef TextDocumentSelectionRangeResult = List<SelectionRange>?;
/// Result for @since 3.16.0
typedef TextDocumentSemanticTokensFullDeltaResult
= Either2<SemanticTokens, SemanticTokensDelta>?;
/// Result for @since 3.16.0
typedef TextDocumentSemanticTokensFullResult = SemanticTokens?;
/// Result for @since 3.16.0
typedef TextDocumentSemanticTokensRangeResult = SemanticTokens?;
typedef TextDocumentSignatureHelpResult = SignatureHelp?;
/// Result for a request to resolve the type definition locations of a symbol at
/// a given text document position. The request's parameter is of type
/// TextDocumentPositionParams the response is of type Definition or a Thenable
/// that resolves to such.
typedef TextDocumentTypeDefinitionResult
= Either2<Definition, List<DefinitionLink>>?;
/// Result for a document will save request is sent from the client to the
/// server before the document is actually saved. The request can return an
/// array of TextEdits which will be applied to the text document before it is
/// saved. Please note that clients might drop results if computing the text
/// edits took too long or if a server constantly fails on this request. This is
/// done to keep the save fast and reliable.
typedef TextDocumentWillSaveWaitUntilResult = List<TextEdit>?;
/// Result for a request to resolve the subtypes for a given
/// `TypeHierarchyItem`.
///
/// @since 3.17.0
typedef TypeHierarchySubtypesResult = List<TypeHierarchyItem>?;
/// Result for a request to resolve the supertypes for a given
/// `TypeHierarchyItem`.
///
/// @since 3.17.0
typedef TypeHierarchySupertypesResult = List<TypeHierarchyItem>?;
/// Result for the show message request is sent from the server to the client to
/// show a message and a set of options actions to the user.
typedef WindowShowMessageRequestResult = MessageActionItem?;
/// A workspace diagnostic document report.
///
/// @since 3.17.0
typedef WorkspaceDocumentDiagnosticReport = Either2<
WorkspaceFullDocumentDiagnosticReport,
WorkspaceUnchangedDocumentDiagnosticReport>;
/// Result for a request send from the client to the server to execute a
/// command. The request might return a workspace edit which the client will
/// apply to the workspace.
typedef WorkspaceExecuteCommandResult = LSPAny?;
/// Result for a request to list project-wide symbols matching the query string
/// given by the WorkspaceSymbolParams. The response is of type
/// [SymbolInformation[]](#SymbolInformation) or a Thenable that resolves to
/// such.
///
/// @since 3.17.0 - support for WorkspaceSymbol in the returned data. Clients
/// need to advertise support for WorkspaceSymbols via the client capability
/// `workspace.symbol.resolveSupport`.
typedef WorkspaceSymbolResult
= Either2<List<SymbolInformation>, List<WorkspaceSymbol>>?;
/// Result for the will create files request is sent from the client to the
/// server before files are actually created as long as the creation is
/// triggered from within the client.
///
/// @since 3.16.0
typedef WorkspaceWillCreateFilesResult = WorkspaceEdit?;
/// Result for the did delete files notification is sent from the client to the
/// server when files were deleted from within the client.
///
/// @since 3.16.0
typedef WorkspaceWillDeleteFilesResult = WorkspaceEdit?;
/// Result for the will rename files request is sent from the client to the
/// server before files are actually renamed as long as the rename is triggered
/// from within the client.
///
/// @since 3.16.0
typedef WorkspaceWillRenameFilesResult = WorkspaceEdit?;
/// Result for the `workspace/workspaceFolders` is sent from the server to the
/// client to fetch the open workspace folders.
typedef WorkspaceWorkspaceFoldersResult = List<WorkspaceFolder>?;
/// A special text edit with an additional change annotation.
///
/// @since 3.16.0.
class AnnotatedTextEdit implements TextEdit, ToJsonable {
static const jsonHandler = LspJsonHandler(
AnnotatedTextEdit.canParse,
AnnotatedTextEdit.fromJson,
);
AnnotatedTextEdit({
required this.annotationId,
required this.newText,
required this.range,
});
static AnnotatedTextEdit fromJson(Map<String, Object?> json) {
final annotationIdJson = json['annotationId'];
final annotationId = annotationIdJson as String;
final newTextJson = json['newText'];
final newText = newTextJson as String;
final rangeJson = json['range'];
final range = Range.fromJson(rangeJson as Map<String, Object?>);
return AnnotatedTextEdit(
annotationId: annotationId,
newText: newText,
range: range,
);
}
/// The actual identifier of the change annotation
final ChangeAnnotationIdentifier annotationId;
/// The string to be inserted. For delete operations use an empty string.
@override
final String newText;
/// The range of the text document to be manipulated. To insert text into a
/// document create a range where start === end.
@override
final Range range;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['annotationId'] = annotationId;
result['newText'] = newText;
result['range'] = range.toJson();
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseString(obj, reporter, 'annotationId',
allowsUndefined: false, allowsNull: false)) {
return false;
}
if (!_canParseString(obj, reporter, 'newText',
allowsUndefined: false, allowsNull: false)) {
return false;
}
return _canParseRange(obj, reporter, 'range',
allowsUndefined: false, allowsNull: false);
} else {
reporter.reportError('must be of type AnnotatedTextEdit');
return false;
}
}
@override
bool operator ==(Object other) {
return other is AnnotatedTextEdit &&
other.runtimeType == AnnotatedTextEdit &&
annotationId == other.annotationId &&
newText == other.newText &&
range == other.range;
}
@override
int get hashCode => Object.hash(
annotationId,
newText,
range,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// The parameters passed via a apply workspace edit request.
class ApplyWorkspaceEditParams implements ToJsonable {
static const jsonHandler = LspJsonHandler(
ApplyWorkspaceEditParams.canParse,
ApplyWorkspaceEditParams.fromJson,
);
ApplyWorkspaceEditParams({
required this.edit,
this.label,
});
static ApplyWorkspaceEditParams fromJson(Map<String, Object?> json) {
final editJson = json['edit'];
final edit = WorkspaceEdit.fromJson(editJson as Map<String, Object?>);
final labelJson = json['label'];
final label = labelJson as String?;
return ApplyWorkspaceEditParams(
edit: edit,
label: label,
);
}
/// The edits to apply.
final WorkspaceEdit edit;
/// An optional label of the workspace edit. This label is presented in the
/// user interface for example on an undo stack to undo the workspace edit.
final String? label;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['edit'] = edit.toJson();
if (label != null) {
result['label'] = label;
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseWorkspaceEdit(obj, reporter, 'edit',
allowsUndefined: false, allowsNull: false)) {
return false;
}
return _canParseString(obj, reporter, 'label',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type ApplyWorkspaceEditParams');
return false;
}
}
@override
bool operator ==(Object other) {
return other is ApplyWorkspaceEditParams &&
other.runtimeType == ApplyWorkspaceEditParams &&
edit == other.edit &&
label == other.label;
}
@override
int get hashCode => Object.hash(
edit,
label,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// The result returned from the apply workspace edit request.
///
/// @since 3.17 renamed from ApplyWorkspaceEditResponse
class ApplyWorkspaceEditResult implements ToJsonable {
static const jsonHandler = LspJsonHandler(
ApplyWorkspaceEditResult.canParse,
ApplyWorkspaceEditResult.fromJson,
);
ApplyWorkspaceEditResult({
required this.applied,
this.failedChange,
this.failureReason,
});
static ApplyWorkspaceEditResult fromJson(Map<String, Object?> json) {
final appliedJson = json['applied'];
final applied = appliedJson as bool;
final failedChangeJson = json['failedChange'];
final failedChange = failedChangeJson as int?;
final failureReasonJson = json['failureReason'];
final failureReason = failureReasonJson as String?;
return ApplyWorkspaceEditResult(
applied: applied,
failedChange: failedChange,
failureReason: failureReason,
);
}
/// Indicates whether the edit was applied or not.
final bool applied;
/// Depending on the client's failure handling strategy `failedChange` might
/// contain the index of the change that failed. This property is only
/// available if the client signals a `failureHandlingStrategy` in its client
/// capabilities.
final int? failedChange;
/// An optional textual description for why the edit was not applied. This may
/// be used by the server for diagnostic logging or to provide a suitable
/// error for a request that triggered the edit.
final String? failureReason;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['applied'] = applied;
if (failedChange != null) {
result['failedChange'] = failedChange;
}
if (failureReason != null) {
result['failureReason'] = failureReason;
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseBool(obj, reporter, 'applied',
allowsUndefined: false, allowsNull: false)) {
return false;
}
if (!_canParseInt(obj, reporter, 'failedChange',
allowsUndefined: true, allowsNull: false)) {
return false;
}
return _canParseString(obj, reporter, 'failureReason',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type ApplyWorkspaceEditResult');
return false;
}
}
@override
bool operator ==(Object other) {
return other is ApplyWorkspaceEditResult &&
other.runtimeType == ApplyWorkspaceEditResult &&
applied == other.applied &&
failedChange == other.failedChange &&
failureReason == other.failureReason;
}
@override
int get hashCode => Object.hash(
applied,
failedChange,
failureReason,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// A base for all symbol information.
class BaseSymbolInformation implements ToJsonable {
static const jsonHandler = LspJsonHandler(
BaseSymbolInformation.canParse,
BaseSymbolInformation.fromJson,
);
BaseSymbolInformation({
this.containerName,
required this.kind,
required this.name,
this.tags,
});
static BaseSymbolInformation fromJson(Map<String, Object?> json) {
if (SymbolInformation.canParse(json, nullLspJsonReporter)) {
return SymbolInformation.fromJson(json);
}
if (WorkspaceSymbol.canParse(json, nullLspJsonReporter)) {
return WorkspaceSymbol.fromJson(json);
}
final containerNameJson = json['containerName'];
final containerName = containerNameJson as String?;
final kindJson = json['kind'];
final kind = SymbolKind.fromJson(kindJson as int);
final nameJson = json['name'];
final name = nameJson as String;
final tagsJson = json['tags'];
final tags = (tagsJson as List<Object?>?)
?.map((item) => SymbolTag.fromJson(item as int))
.toList();
return BaseSymbolInformation(
containerName: containerName,
kind: kind,
name: name,
tags: tags,
);
}
/// The name of the symbol containing this symbol. This information is for
/// user interface purposes (e.g. to render a qualifier in the user interface
/// if necessary). It can't be used to re-infer a hierarchy for the document
/// symbols.
final String? containerName;
/// The kind of this symbol.
final SymbolKind kind;
/// The name of this symbol.
final String name;
/// Tags for this symbol.
///
/// @since 3.16.0
final List<SymbolTag>? tags;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
if (containerName != null) {
result['containerName'] = containerName;
}
result['kind'] = kind.toJson();
result['name'] = name;
if (tags != null) {
result['tags'] = tags?.map((item) => item.toJson()).toList();
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseString(obj, reporter, 'containerName',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseSymbolKind(obj, reporter, 'kind',
allowsUndefined: false, allowsNull: false)) {
return false;
}
if (!_canParseString(obj, reporter, 'name',
allowsUndefined: false, allowsNull: false)) {
return false;
}
return _canParseListSymbolTag(obj, reporter, 'tags',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type BaseSymbolInformation');
return false;
}
}
@override
bool operator ==(Object other) {
return other is BaseSymbolInformation &&
other.runtimeType == BaseSymbolInformation &&
containerName == other.containerName &&
kind == other.kind &&
name == other.name &&
listEqual(tags, other.tags, (SymbolTag a, SymbolTag b) => a == b);
}
@override
int get hashCode => Object.hash(
containerName,
kind,
name,
lspHashCode(tags),
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// @since 3.16.0
class CallHierarchyClientCapabilities implements ToJsonable {
static const jsonHandler = LspJsonHandler(
CallHierarchyClientCapabilities.canParse,
CallHierarchyClientCapabilities.fromJson,
);
CallHierarchyClientCapabilities({
this.dynamicRegistration,
});
static CallHierarchyClientCapabilities fromJson(Map<String, Object?> json) {
final dynamicRegistrationJson = json['dynamicRegistration'];
final dynamicRegistration = dynamicRegistrationJson as bool?;
return CallHierarchyClientCapabilities(
dynamicRegistration: dynamicRegistration,
);
}
/// Whether implementation supports dynamic registration. If this is set to
/// `true` the client supports the new `(TextDocumentRegistrationOptions &
/// StaticRegistrationOptions)` return value for the corresponding server
/// capability as well.
final bool? dynamicRegistration;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
if (dynamicRegistration != null) {
result['dynamicRegistration'] = dynamicRegistration;
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
return _canParseBool(obj, reporter, 'dynamicRegistration',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type CallHierarchyClientCapabilities');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CallHierarchyClientCapabilities &&
other.runtimeType == CallHierarchyClientCapabilities &&
dynamicRegistration == other.dynamicRegistration;
}
@override
int get hashCode => dynamicRegistration.hashCode;
@override
String toString() => jsonEncoder.convert(toJson());
}
/// Represents an incoming call, e.g. a caller of a method or constructor.
///
/// @since 3.16.0
class CallHierarchyIncomingCall implements ToJsonable {
static const jsonHandler = LspJsonHandler(
CallHierarchyIncomingCall.canParse,
CallHierarchyIncomingCall.fromJson,
);
CallHierarchyIncomingCall({
required this.from,
required this.fromRanges,
});
static CallHierarchyIncomingCall fromJson(Map<String, Object?> json) {
final fromJson = json['from'];
final from = CallHierarchyItem.fromJson(fromJson as Map<String, Object?>);
final fromRangesJson = json['fromRanges'];
final fromRanges = (fromRangesJson as List<Object?>)
.map((item) => Range.fromJson(item as Map<String, Object?>))
.toList();
return CallHierarchyIncomingCall(
from: from,
fromRanges: fromRanges,
);
}
/// The item that makes the call.
final CallHierarchyItem from;
/// The ranges at which the calls appear. This is relative to the caller
/// denoted by `this.from`.
final List<Range> fromRanges;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['from'] = from.toJson();
result['fromRanges'] = fromRanges.map((item) => item.toJson()).toList();
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseCallHierarchyItem(obj, reporter, 'from',
allowsUndefined: false, allowsNull: false)) {
return false;
}
return _canParseListRange(obj, reporter, 'fromRanges',
allowsUndefined: false, allowsNull: false);
} else {
reporter.reportError('must be of type CallHierarchyIncomingCall');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CallHierarchyIncomingCall &&
other.runtimeType == CallHierarchyIncomingCall &&
from == other.from &&
listEqual(fromRanges, other.fromRanges, (Range a, Range b) => a == b);
}
@override
int get hashCode => Object.hash(
from,
lspHashCode(fromRanges),
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// The parameter of a `callHierarchy/incomingCalls` request.
///
/// @since 3.16.0
class CallHierarchyIncomingCallsParams
implements PartialResultParams, WorkDoneProgressParams, ToJsonable {
static const jsonHandler = LspJsonHandler(
CallHierarchyIncomingCallsParams.canParse,
CallHierarchyIncomingCallsParams.fromJson,
);
CallHierarchyIncomingCallsParams({
required this.item,
this.partialResultToken,
this.workDoneToken,
});
static CallHierarchyIncomingCallsParams fromJson(Map<String, Object?> json) {
final itemJson = json['item'];
final item = CallHierarchyItem.fromJson(itemJson as Map<String, Object?>);
final partialResultTokenJson = json['partialResultToken'];
final partialResultToken = partialResultTokenJson == null
? null
: _eitherIntString(partialResultTokenJson);
final workDoneTokenJson = json['workDoneToken'];
final workDoneToken =
workDoneTokenJson == null ? null : _eitherIntString(workDoneTokenJson);
return CallHierarchyIncomingCallsParams(
item: item,
partialResultToken: partialResultToken,
workDoneToken: workDoneToken,
);
}
final CallHierarchyItem item;
/// An optional token that a server can use to report partial results (e.g.
/// streaming) to the client.
@override
final ProgressToken? partialResultToken;
/// An optional token that a server can use to report work done progress.
@override
final ProgressToken? workDoneToken;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['item'] = item.toJson();
if (partialResultToken != null) {
result['partialResultToken'] = partialResultToken;
}
if (workDoneToken != null) {
result['workDoneToken'] = workDoneToken;
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseCallHierarchyItem(obj, reporter, 'item',
allowsUndefined: false, allowsNull: false)) {
return false;
}
if (!_canParseIntString(obj, reporter, 'partialResultToken',
allowsUndefined: true, allowsNull: false)) {
return false;
}
return _canParseIntString(obj, reporter, 'workDoneToken',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type CallHierarchyIncomingCallsParams');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CallHierarchyIncomingCallsParams &&
other.runtimeType == CallHierarchyIncomingCallsParams &&
item == other.item &&
partialResultToken == other.partialResultToken &&
workDoneToken == other.workDoneToken;
}
@override
int get hashCode => Object.hash(
item,
partialResultToken,
workDoneToken,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// Represents programming constructs like functions or constructors in the
/// context of call hierarchy.
///
/// @since 3.16.0
class CallHierarchyItem implements ToJsonable {
static const jsonHandler = LspJsonHandler(
CallHierarchyItem.canParse,
CallHierarchyItem.fromJson,
);
CallHierarchyItem({
this.data,
this.detail,
required this.kind,
required this.name,
required this.range,
required this.selectionRange,
this.tags,
required this.uri,
});
static CallHierarchyItem fromJson(Map<String, Object?> json) {
final dataJson = json['data'];
final data = dataJson;
final detailJson = json['detail'];
final detail = detailJson as String?;
final kindJson = json['kind'];
final kind = SymbolKind.fromJson(kindJson as int);
final nameJson = json['name'];
final name = nameJson as String;
final rangeJson = json['range'];
final range = Range.fromJson(rangeJson as Map<String, Object?>);
final selectionRangeJson = json['selectionRange'];
final selectionRange =
Range.fromJson(selectionRangeJson as Map<String, Object?>);
final tagsJson = json['tags'];
final tags = (tagsJson as List<Object?>?)
?.map((item) => SymbolTag.fromJson(item as int))
.toList();
final uriJson = json['uri'];
final uri = uriJson as String;
return CallHierarchyItem(
data: data,
detail: detail,
kind: kind,
name: name,
range: range,
selectionRange: selectionRange,
tags: tags,
uri: uri,
);
}
/// A data entry field that is preserved between a call hierarchy prepare and
/// incoming calls or outgoing calls requests.
final LSPAny data;
/// More detail for this item, e.g. the signature of a function.
final String? detail;
/// The kind of this item.
final SymbolKind kind;
/// The name of this item.
final String name;
/// The range enclosing this symbol not including leading/trailing whitespace
/// but everything else, e.g. comments and code.
final Range range;
/// The range that should be selected and revealed when this symbol is being
/// picked, e.g. the name of a function. Must be contained by the `range`.
final Range selectionRange;
/// Tags for this item.
final List<SymbolTag>? tags;
/// The resource identifier of this item.
final DocumentUri uri;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
if (data != null) {
result['data'] = data;
}
if (detail != null) {
result['detail'] = detail;
}
result['kind'] = kind.toJson();
result['name'] = name;
result['range'] = range.toJson();
result['selectionRange'] = selectionRange.toJson();
if (tags != null) {
result['tags'] = tags?.map((item) => item.toJson()).toList();
}
result['uri'] = uri;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseString(obj, reporter, 'detail',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseSymbolKind(obj, reporter, 'kind',
allowsUndefined: false, allowsNull: false)) {
return false;
}
if (!_canParseString(obj, reporter, 'name',
allowsUndefined: false, allowsNull: false)) {
return false;
}
if (!_canParseRange(obj, reporter, 'range',
allowsUndefined: false, allowsNull: false)) {
return false;
}
if (!_canParseRange(obj, reporter, 'selectionRange',
allowsUndefined: false, allowsNull: false)) {
return false;
}
if (!_canParseListSymbolTag(obj, reporter, 'tags',
allowsUndefined: true, allowsNull: false)) {
return false;
}
return _canParseString(obj, reporter, 'uri',
allowsUndefined: false, allowsNull: false);
} else {
reporter.reportError('must be of type CallHierarchyItem');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CallHierarchyItem &&
other.runtimeType == CallHierarchyItem &&
data == other.data &&
detail == other.detail &&
kind == other.kind &&
name == other.name &&
range == other.range &&
selectionRange == other.selectionRange &&
listEqual(tags, other.tags, (SymbolTag a, SymbolTag b) => a == b) &&
uri == other.uri;
}
@override
int get hashCode => Object.hash(
data,
detail,
kind,
name,
range,
selectionRange,
lspHashCode(tags),
uri,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// Call hierarchy options used during static registration.
///
/// @since 3.16.0
class CallHierarchyOptions implements WorkDoneProgressOptions, ToJsonable {
static const jsonHandler = LspJsonHandler(
CallHierarchyOptions.canParse,
CallHierarchyOptions.fromJson,
);
CallHierarchyOptions({
this.workDoneProgress,
});
static CallHierarchyOptions fromJson(Map<String, Object?> json) {
if (CallHierarchyRegistrationOptions.canParse(json, nullLspJsonReporter)) {
return CallHierarchyRegistrationOptions.fromJson(json);
}
final workDoneProgressJson = json['workDoneProgress'];
final workDoneProgress = workDoneProgressJson as bool?;
return CallHierarchyOptions(
workDoneProgress: workDoneProgress,
);
}
@override
final bool? workDoneProgress;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
if (workDoneProgress != null) {
result['workDoneProgress'] = workDoneProgress;
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
return _canParseBool(obj, reporter, 'workDoneProgress',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type CallHierarchyOptions');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CallHierarchyOptions &&
other.runtimeType == CallHierarchyOptions &&
workDoneProgress == other.workDoneProgress;
}
@override
int get hashCode => workDoneProgress.hashCode;
@override
String toString() => jsonEncoder.convert(toJson());
}
/// Represents an outgoing call, e.g. calling a getter from a method or a method
/// from a constructor etc.
///
/// @since 3.16.0
class CallHierarchyOutgoingCall implements ToJsonable {
static const jsonHandler = LspJsonHandler(
CallHierarchyOutgoingCall.canParse,
CallHierarchyOutgoingCall.fromJson,
);
CallHierarchyOutgoingCall({
required this.fromRanges,
required this.to,
});
static CallHierarchyOutgoingCall fromJson(Map<String, Object?> json) {
final fromRangesJson = json['fromRanges'];
final fromRanges = (fromRangesJson as List<Object?>)
.map((item) => Range.fromJson(item as Map<String, Object?>))
.toList();
final toJson = json['to'];
final to = CallHierarchyItem.fromJson(toJson as Map<String, Object?>);
return CallHierarchyOutgoingCall(
fromRanges: fromRanges,
to: to,
);
}
/// The range at which this item is called. This is the range relative to the
/// caller, e.g the item passed to `provideCallHierarchyOutgoingCalls` and not
/// `this.to`.
final List<Range> fromRanges;
/// The item that is called.
final CallHierarchyItem to;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['fromRanges'] = fromRanges.map((item) => item.toJson()).toList();
result['to'] = to.toJson();
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseListRange(obj, reporter, 'fromRanges',
allowsUndefined: false, allowsNull: false)) {
return false;
}
return _canParseCallHierarchyItem(obj, reporter, 'to',
allowsUndefined: false, allowsNull: false);
} else {
reporter.reportError('must be of type CallHierarchyOutgoingCall');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CallHierarchyOutgoingCall &&
other.runtimeType == CallHierarchyOutgoingCall &&
listEqual(fromRanges, other.fromRanges, (Range a, Range b) => a == b) &&
to == other.to;
}
@override
int get hashCode => Object.hash(
lspHashCode(fromRanges),
to,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// The parameter of a `callHierarchy/outgoingCalls` request.
///
/// @since 3.16.0
class CallHierarchyOutgoingCallsParams
implements PartialResultParams, WorkDoneProgressParams, ToJsonable {
static const jsonHandler = LspJsonHandler(
CallHierarchyOutgoingCallsParams.canParse,
CallHierarchyOutgoingCallsParams.fromJson,
);
CallHierarchyOutgoingCallsParams({
required this.item,
this.partialResultToken,
this.workDoneToken,
});
static CallHierarchyOutgoingCallsParams fromJson(Map<String, Object?> json) {
final itemJson = json['item'];
final item = CallHierarchyItem.fromJson(itemJson as Map<String, Object?>);
final partialResultTokenJson = json['partialResultToken'];
final partialResultToken = partialResultTokenJson == null
? null
: _eitherIntString(partialResultTokenJson);
final workDoneTokenJson = json['workDoneToken'];
final workDoneToken =
workDoneTokenJson == null ? null : _eitherIntString(workDoneTokenJson);
return CallHierarchyOutgoingCallsParams(
item: item,
partialResultToken: partialResultToken,
workDoneToken: workDoneToken,
);
}
final CallHierarchyItem item;
/// An optional token that a server can use to report partial results (e.g.
/// streaming) to the client.
@override
final ProgressToken? partialResultToken;
/// An optional token that a server can use to report work done progress.
@override
final ProgressToken? workDoneToken;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['item'] = item.toJson();
if (partialResultToken != null) {
result['partialResultToken'] = partialResultToken;
}
if (workDoneToken != null) {
result['workDoneToken'] = workDoneToken;
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseCallHierarchyItem(obj, reporter, 'item',
allowsUndefined: false, allowsNull: false)) {
return false;
}
if (!_canParseIntString(obj, reporter, 'partialResultToken',
allowsUndefined: true, allowsNull: false)) {
return false;
}
return _canParseIntString(obj, reporter, 'workDoneToken',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type CallHierarchyOutgoingCallsParams');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CallHierarchyOutgoingCallsParams &&
other.runtimeType == CallHierarchyOutgoingCallsParams &&
item == other.item &&
partialResultToken == other.partialResultToken &&
workDoneToken == other.workDoneToken;
}
@override
int get hashCode => Object.hash(
item,
partialResultToken,
workDoneToken,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// The parameter of a `textDocument/prepareCallHierarchy` request.
///
/// @since 3.16.0
class CallHierarchyPrepareParams
implements TextDocumentPositionParams, WorkDoneProgressParams, ToJsonable {
static const jsonHandler = LspJsonHandler(
CallHierarchyPrepareParams.canParse,
CallHierarchyPrepareParams.fromJson,
);
CallHierarchyPrepareParams({
required this.position,
required this.textDocument,
this.workDoneToken,
});
static CallHierarchyPrepareParams fromJson(Map<String, Object?> json) {
final positionJson = json['position'];
final position = Position.fromJson(positionJson as Map<String, Object?>);
final textDocumentJson = json['textDocument'];
final textDocument = TextDocumentIdentifier.fromJson(
textDocumentJson as Map<String, Object?>);
final workDoneTokenJson = json['workDoneToken'];
final workDoneToken =
workDoneTokenJson == null ? null : _eitherIntString(workDoneTokenJson);
return CallHierarchyPrepareParams(
position: position,
textDocument: textDocument,
workDoneToken: workDoneToken,
);
}
/// The position inside the text document.
@override
final Position position;
/// The text document.
@override
final TextDocumentIdentifier textDocument;
/// An optional token that a server can use to report work done progress.
@override
final ProgressToken? workDoneToken;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['position'] = position.toJson();
result['textDocument'] = textDocument.toJson();
if (workDoneToken != null) {
result['workDoneToken'] = workDoneToken;
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParsePosition(obj, reporter, 'position',
allowsUndefined: false, allowsNull: false)) {
return false;
}
if (!_canParseTextDocumentIdentifier(obj, reporter, 'textDocument',
allowsUndefined: false, allowsNull: false)) {
return false;
}
return _canParseIntString(obj, reporter, 'workDoneToken',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type CallHierarchyPrepareParams');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CallHierarchyPrepareParams &&
other.runtimeType == CallHierarchyPrepareParams &&
position == other.position &&
textDocument == other.textDocument &&
workDoneToken == other.workDoneToken;
}
@override
int get hashCode => Object.hash(
position,
textDocument,
workDoneToken,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// Call hierarchy options used during static or dynamic registration.
///
/// @since 3.16.0
class CallHierarchyRegistrationOptions
implements
CallHierarchyOptions,
StaticRegistrationOptions,
TextDocumentRegistrationOptions,
ToJsonable {
static const jsonHandler = LspJsonHandler(
CallHierarchyRegistrationOptions.canParse,
CallHierarchyRegistrationOptions.fromJson,
);
CallHierarchyRegistrationOptions({
this.documentSelector,
this.id,
this.workDoneProgress,
});
static CallHierarchyRegistrationOptions fromJson(Map<String, Object?> json) {
final documentSelectorJson = json['documentSelector'];
final documentSelector = (documentSelectorJson as List<Object?>?)
?.map((item) =>
TextDocumentFilterWithScheme.fromJson(item as Map<String, Object?>))
.toList();
final idJson = json['id'];
final id = idJson as String?;
final workDoneProgressJson = json['workDoneProgress'];
final workDoneProgress = workDoneProgressJson as bool?;
return CallHierarchyRegistrationOptions(
documentSelector: documentSelector,
id: id,
workDoneProgress: workDoneProgress,
);
}
/// A document selector to identify the scope of the registration. If set to
/// null the document selector provided on the client side will be used.
@override
final List<TextDocumentFilterWithScheme>? documentSelector;
/// The id used to register the request. The id can be used to deregister the
/// request again. See also Registration#id.
@override
final String? id;
@override
final bool? workDoneProgress;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['documentSelector'] = documentSelector;
if (id != null) {
result['id'] = id;
}
if (workDoneProgress != null) {
result['workDoneProgress'] = workDoneProgress;
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseListTextDocumentFilterWithScheme(
obj, reporter, 'documentSelector',
allowsUndefined: false, allowsNull: true)) {
return false;
}
if (!_canParseString(obj, reporter, 'id',
allowsUndefined: true, allowsNull: false)) {
return false;
}
return _canParseBool(obj, reporter, 'workDoneProgress',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type CallHierarchyRegistrationOptions');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CallHierarchyRegistrationOptions &&
other.runtimeType == CallHierarchyRegistrationOptions &&
listEqual(
documentSelector,
other.documentSelector,
(TextDocumentFilterWithScheme a, TextDocumentFilterWithScheme b) =>
a == b) &&
id == other.id &&
workDoneProgress == other.workDoneProgress;
}
@override
int get hashCode => Object.hash(
lspHashCode(documentSelector),
id,
workDoneProgress,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
class CancelParams implements ToJsonable {
static const jsonHandler = LspJsonHandler(
CancelParams.canParse,
CancelParams.fromJson,
);
CancelParams({
required this.id,
});
static CancelParams fromJson(Map<String, Object?> json) {
final idJson = json['id'];
final id = _eitherIntString(idJson);
return CancelParams(
id: id,
);
}
/// The request id to cancel.
final Either2<int, String> id;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['id'] = id;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
return _canParseIntString(obj, reporter, 'id',
allowsUndefined: false, allowsNull: false);
} else {
reporter.reportError('must be of type CancelParams');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CancelParams &&
other.runtimeType == CancelParams &&
id == other.id;
}
@override
int get hashCode => id.hashCode;
@override
String toString() => jsonEncoder.convert(toJson());
}
/// Additional information that describes document changes.
///
/// @since 3.16.0
class ChangeAnnotation implements ToJsonable {
static const jsonHandler = LspJsonHandler(
ChangeAnnotation.canParse,
ChangeAnnotation.fromJson,
);
ChangeAnnotation({
this.description,
required this.label,
this.needsConfirmation,
});
static ChangeAnnotation fromJson(Map<String, Object?> json) {
final descriptionJson = json['description'];
final description = descriptionJson as String?;
final labelJson = json['label'];
final label = labelJson as String;
final needsConfirmationJson = json['needsConfirmation'];
final needsConfirmation = needsConfirmationJson as bool?;
return ChangeAnnotation(
description: description,
label: label,
needsConfirmation: needsConfirmation,
);
}
/// A human-readable string which is rendered less prominent in the user
/// interface.
final String? description;
/// A human-readable string describing the actual change. The string is
/// rendered prominent in the user interface.
final String label;
/// A flag which indicates that user confirmation is needed before applying
/// the change.
final bool? needsConfirmation;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
if (description != null) {
result['description'] = description;
}
result['label'] = label;
if (needsConfirmation != null) {
result['needsConfirmation'] = needsConfirmation;
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseString(obj, reporter, 'description',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseString(obj, reporter, 'label',
allowsUndefined: false, allowsNull: false)) {
return false;
}
return _canParseBool(obj, reporter, 'needsConfirmation',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type ChangeAnnotation');
return false;
}
}
@override
bool operator ==(Object other) {
return other is ChangeAnnotation &&
other.runtimeType == ChangeAnnotation &&
description == other.description &&
label == other.label &&
needsConfirmation == other.needsConfirmation;
}
@override
int get hashCode => Object.hash(
description,
label,
needsConfirmation,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// Defines the capabilities provided by the client.
class ClientCapabilities implements ToJsonable {
static const jsonHandler = LspJsonHandler(
ClientCapabilities.canParse,
ClientCapabilities.fromJson,
);
ClientCapabilities({
this.experimental,
this.general,
this.notebookDocument,
this.textDocument,
this.window,
this.workspace,
});
static ClientCapabilities fromJson(Map<String, Object?> json) {
final experimentalJson = json['experimental'];
final experimental = experimentalJson;
final generalJson = json['general'];
final general = generalJson != null
? GeneralClientCapabilities.fromJson(
generalJson as Map<String, Object?>)
: null;
final notebookDocumentJson = json['notebookDocument'];
final notebookDocument = notebookDocumentJson != null
? NotebookDocumentClientCapabilities.fromJson(
notebookDocumentJson as Map<String, Object?>)
: null;
final textDocumentJson = json['textDocument'];
final textDocument = textDocumentJson != null
? TextDocumentClientCapabilities.fromJson(
textDocumentJson as Map<String, Object?>)
: null;
final windowJson = json['window'];
final window = windowJson != null
? WindowClientCapabilities.fromJson(windowJson as Map<String, Object?>)
: null;
final workspaceJson = json['workspace'];
final workspace = workspaceJson != null
? WorkspaceClientCapabilities.fromJson(
workspaceJson as Map<String, Object?>)
: null;
return ClientCapabilities(
experimental: experimental,
general: general,
notebookDocument: notebookDocument,
textDocument: textDocument,
window: window,
workspace: workspace,
);
}
/// Experimental client capabilities.
final LSPAny experimental;
/// General client capabilities.
///
/// @since 3.16.0
final GeneralClientCapabilities? general;
/// Capabilities specific to the notebook document support.
///
/// @since 3.17.0
final NotebookDocumentClientCapabilities? notebookDocument;
/// Text document specific client capabilities.
final TextDocumentClientCapabilities? textDocument;
/// Window specific client capabilities.
final WindowClientCapabilities? window;
/// Workspace specific client capabilities.
final WorkspaceClientCapabilities? workspace;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
if (experimental != null) {
result['experimental'] = experimental;
}
if (general != null) {
result['general'] = general?.toJson();
}
if (notebookDocument != null) {
result['notebookDocument'] = notebookDocument?.toJson();
}
if (textDocument != null) {
result['textDocument'] = textDocument?.toJson();
}
if (window != null) {
result['window'] = window?.toJson();
}
if (workspace != null) {
result['workspace'] = workspace?.toJson();
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseGeneralClientCapabilities(obj, reporter, 'general',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseNotebookDocumentClientCapabilities(
obj, reporter, 'notebookDocument',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseTextDocumentClientCapabilities(
obj, reporter, 'textDocument',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseWindowClientCapabilities(obj, reporter, 'window',
allowsUndefined: true, allowsNull: false)) {
return false;
}
return _canParseWorkspaceClientCapabilities(obj, reporter, 'workspace',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type ClientCapabilities');
return false;
}
}
@override
bool operator ==(Object other) {
return other is ClientCapabilities &&
other.runtimeType == ClientCapabilities &&
experimental == other.experimental &&
general == other.general &&
notebookDocument == other.notebookDocument &&
textDocument == other.textDocument &&
window == other.window &&
workspace == other.workspace;
}
@override
int get hashCode => Object.hash(
experimental,
general,
notebookDocument,
textDocument,
window,
workspace,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// A code action represents a change that can be performed in code, e.g. to fix
/// a problem or to refactor code.
///
/// A CodeAction must set either `edit` and/or a `command`. If both are
/// supplied, the `edit` is applied first, then the `command` is executed.
class CodeAction implements ToJsonable {
static const jsonHandler = LspJsonHandler(
CodeAction.canParse,
CodeAction.fromJson,
);
CodeAction({
this.command,
this.data,
this.diagnostics,
this.disabled,
this.edit,
this.isPreferred,
this.kind,
required this.title,
});
static CodeAction fromJson(Map<String, Object?> json) {
final commandJson = json['command'];
final command = commandJson != null
? Command.fromJson(commandJson as Map<String, Object?>)
: null;
final dataJson = json['data'];
final data = dataJson;
final diagnosticsJson = json['diagnostics'];
final diagnostics = (diagnosticsJson as List<Object?>?)
?.map((item) => Diagnostic.fromJson(item as Map<String, Object?>))
.toList();
final disabledJson = json['disabled'];
final disabled = disabledJson != null
? CodeActionDisabled.fromJson(disabledJson as Map<String, Object?>)
: null;
final editJson = json['edit'];
final edit = editJson != null
? WorkspaceEdit.fromJson(editJson as Map<String, Object?>)
: null;
final isPreferredJson = json['isPreferred'];
final isPreferred = isPreferredJson as bool?;
final kindJson = json['kind'];
final kind =
kindJson != null ? CodeActionKind.fromJson(kindJson as String) : null;
final titleJson = json['title'];
final title = titleJson as String;
return CodeAction(
command: command,
data: data,
diagnostics: diagnostics,
disabled: disabled,
edit: edit,
isPreferred: isPreferred,
kind: kind,
title: title,
);
}
/// A command this code action executes. If a code action provides an edit and
/// a command, first the edit is executed and then the command.
final Command? command;
/// A data entry field that is preserved on a code action between a
/// `textDocument/codeAction` and a `codeAction/resolve` request.
///
/// @since 3.16.0
final LSPAny data;
/// The diagnostics that this code action resolves.
final List<Diagnostic>? diagnostics;
/// Marks that the code action cannot currently be applied.
///
/// Clients should follow the following guidelines regarding disabled code
/// actions:
///
/// - Disabled code actions are not shown in automatic
/// [lightbulbs](https://code.visualstudio.com/docs/editor/editingevolved#_code-action)
/// code action menus.
///
/// - Disabled actions are shown as faded out in the code action menu when
/// the user requests a more specific type
/// of code action, such as refactorings.
///
/// - If the user has a
/// [keybinding](https://code.visualstudio.com/docs/editor/refactoring#_keybindings-for-code-actions)
/// that auto applies a code action and only disabled code actions are
/// returned, the client should show the user an
/// error message with `reason` in the editor.
///
/// @since 3.16.0
final CodeActionDisabled? disabled;
/// The workspace edit this code action performs.
final WorkspaceEdit? edit;
/// Marks this as a preferred action. Preferred actions are used by the `auto
/// fix` command and can be targeted by keybindings.
///
/// A quick fix should be marked preferred if it properly addresses the
/// underlying error. A refactoring should be marked preferred if it is the
/// most reasonable choice of actions to take.
///
/// @since 3.15.0
final bool? isPreferred;
/// The kind of the code action.
///
/// Used to filter code actions.
final CodeActionKind? kind;
/// A short, human-readable, title for this code action.
final String title;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
if (command != null) {
result['command'] = command?.toJson();
}
if (data != null) {
result['data'] = data;
}
if (diagnostics != null) {
result['diagnostics'] =
diagnostics?.map((item) => item.toJson()).toList();
}
if (disabled != null) {
result['disabled'] = disabled?.toJson();
}
if (edit != null) {
result['edit'] = edit?.toJson();
}
if (isPreferred != null) {
result['isPreferred'] = isPreferred;
}
if (kind != null) {
result['kind'] = kind?.toJson();
}
result['title'] = title;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseCommand(obj, reporter, 'command',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseListDiagnostic(obj, reporter, 'diagnostics',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseCodeActionDisabled(obj, reporter, 'disabled',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseWorkspaceEdit(obj, reporter, 'edit',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseBool(obj, reporter, 'isPreferred',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseCodeActionKind(obj, reporter, 'kind',
allowsUndefined: true, allowsNull: false)) {
return false;
}
return _canParseString(obj, reporter, 'title',
allowsUndefined: false, allowsNull: false);
} else {
reporter.reportError('must be of type CodeAction');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CodeAction &&
other.runtimeType == CodeAction &&
command == other.command &&
data == other.data &&
listEqual(diagnostics, other.diagnostics,
(Diagnostic a, Diagnostic b) => a == b) &&
disabled == other.disabled &&
edit == other.edit &&
isPreferred == other.isPreferred &&
kind == other.kind &&
title == other.title;
}
@override
int get hashCode => Object.hash(
command,
data,
lspHashCode(diagnostics),
disabled,
edit,
isPreferred,
kind,
title,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// The Client Capabilities of a CodeActionRequest.
class CodeActionClientCapabilities implements ToJsonable {
static const jsonHandler = LspJsonHandler(
CodeActionClientCapabilities.canParse,
CodeActionClientCapabilities.fromJson,
);
CodeActionClientCapabilities({
this.codeActionLiteralSupport,
this.dataSupport,
this.disabledSupport,
this.dynamicRegistration,
this.honorsChangeAnnotations,
this.isPreferredSupport,
this.resolveSupport,
});
static CodeActionClientCapabilities fromJson(Map<String, Object?> json) {
final codeActionLiteralSupportJson = json['codeActionLiteralSupport'];
final codeActionLiteralSupport = codeActionLiteralSupportJson != null
? CodeActionClientCapabilitiesCodeActionLiteralSupport.fromJson(
codeActionLiteralSupportJson as Map<String, Object?>)
: null;
final dataSupportJson = json['dataSupport'];
final dataSupport = dataSupportJson as bool?;
final disabledSupportJson = json['disabledSupport'];
final disabledSupport = disabledSupportJson as bool?;
final dynamicRegistrationJson = json['dynamicRegistration'];
final dynamicRegistration = dynamicRegistrationJson as bool?;
final honorsChangeAnnotationsJson = json['honorsChangeAnnotations'];
final honorsChangeAnnotations = honorsChangeAnnotationsJson as bool?;
final isPreferredSupportJson = json['isPreferredSupport'];
final isPreferredSupport = isPreferredSupportJson as bool?;
final resolveSupportJson = json['resolveSupport'];
final resolveSupport = resolveSupportJson != null
? CodeActionClientCapabilitiesResolveSupport.fromJson(
resolveSupportJson as Map<String, Object?>)
: null;
return CodeActionClientCapabilities(
codeActionLiteralSupport: codeActionLiteralSupport,
dataSupport: dataSupport,
disabledSupport: disabledSupport,
dynamicRegistration: dynamicRegistration,
honorsChangeAnnotations: honorsChangeAnnotations,
isPreferredSupport: isPreferredSupport,
resolveSupport: resolveSupport,
);
}
/// The client support code action literals of type `CodeAction` as a valid
/// response of the `textDocument/codeAction` request. If the property is not
/// set the request can only return `Command` literals.
///
/// @since 3.8.0
final CodeActionClientCapabilitiesCodeActionLiteralSupport?
codeActionLiteralSupport;
/// Whether code action supports the `data` property which is preserved
/// between a `textDocument/codeAction` and a `codeAction/resolve` request.
///
/// @since 3.16.0
final bool? dataSupport;
/// Whether code action supports the `disabled` property.
///
/// @since 3.16.0
final bool? disabledSupport;
/// Whether code action supports dynamic registration.
final bool? dynamicRegistration;
/// Whether the client honors the change annotations in text edits and
/// resource operations returned via the `CodeAction#edit` property by for
/// example presenting the workspace edit in the user interface and asking for
/// confirmation.
///
/// @since 3.16.0
final bool? honorsChangeAnnotations;
/// Whether code action supports the `isPreferred` property.
///
/// @since 3.15.0
final bool? isPreferredSupport;
/// Whether the client supports resolving additional code action properties
/// via a separate `codeAction/resolve` request.
///
/// @since 3.16.0
final CodeActionClientCapabilitiesResolveSupport? resolveSupport;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
if (codeActionLiteralSupport != null) {
result['codeActionLiteralSupport'] = codeActionLiteralSupport?.toJson();
}
if (dataSupport != null) {
result['dataSupport'] = dataSupport;
}
if (disabledSupport != null) {
result['disabledSupport'] = disabledSupport;
}
if (dynamicRegistration != null) {
result['dynamicRegistration'] = dynamicRegistration;
}
if (honorsChangeAnnotations != null) {
result['honorsChangeAnnotations'] = honorsChangeAnnotations;
}
if (isPreferredSupport != null) {
result['isPreferredSupport'] = isPreferredSupport;
}
if (resolveSupport != null) {
result['resolveSupport'] = resolveSupport?.toJson();
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseCodeActionClientCapabilitiesCodeActionLiteralSupport(
obj, reporter, 'codeActionLiteralSupport',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseBool(obj, reporter, 'dataSupport',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseBool(obj, reporter, 'disabledSupport',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseBool(obj, reporter, 'dynamicRegistration',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseBool(obj, reporter, 'honorsChangeAnnotations',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseBool(obj, reporter, 'isPreferredSupport',
allowsUndefined: true, allowsNull: false)) {
return false;
}
return _canParseCodeActionClientCapabilitiesResolveSupport(
obj, reporter, 'resolveSupport',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type CodeActionClientCapabilities');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CodeActionClientCapabilities &&
other.runtimeType == CodeActionClientCapabilities &&
codeActionLiteralSupport == other.codeActionLiteralSupport &&
dataSupport == other.dataSupport &&
disabledSupport == other.disabledSupport &&
dynamicRegistration == other.dynamicRegistration &&
honorsChangeAnnotations == other.honorsChangeAnnotations &&
isPreferredSupport == other.isPreferredSupport &&
resolveSupport == other.resolveSupport;
}
@override
int get hashCode => Object.hash(
codeActionLiteralSupport,
dataSupport,
disabledSupport,
dynamicRegistration,
honorsChangeAnnotations,
isPreferredSupport,
resolveSupport,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
class CodeActionClientCapabilitiesCodeActionLiteralSupport
implements ToJsonable {
static const jsonHandler = LspJsonHandler(
CodeActionClientCapabilitiesCodeActionLiteralSupport.canParse,
CodeActionClientCapabilitiesCodeActionLiteralSupport.fromJson,
);
CodeActionClientCapabilitiesCodeActionLiteralSupport({
required this.codeActionKind,
});
static CodeActionClientCapabilitiesCodeActionLiteralSupport fromJson(
Map<String, Object?> json) {
final codeActionKindJson = json['codeActionKind'];
final codeActionKind = CodeActionLiteralSupportCodeActionKind.fromJson(
codeActionKindJson as Map<String, Object?>);
return CodeActionClientCapabilitiesCodeActionLiteralSupport(
codeActionKind: codeActionKind,
);
}
/// The code action kind is support with the following value set.
final CodeActionLiteralSupportCodeActionKind codeActionKind;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['codeActionKind'] = codeActionKind.toJson();
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
return _canParseCodeActionLiteralSupportCodeActionKind(
obj, reporter, 'codeActionKind',
allowsUndefined: false, allowsNull: false);
} else {
reporter.reportError(
'must be of type CodeActionClientCapabilitiesCodeActionLiteralSupport');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CodeActionClientCapabilitiesCodeActionLiteralSupport &&
other.runtimeType ==
CodeActionClientCapabilitiesCodeActionLiteralSupport &&
codeActionKind == other.codeActionKind;
}
@override
int get hashCode => codeActionKind.hashCode;
@override
String toString() => jsonEncoder.convert(toJson());
}
class CodeActionClientCapabilitiesResolveSupport implements ToJsonable {
static const jsonHandler = LspJsonHandler(
CodeActionClientCapabilitiesResolveSupport.canParse,
CodeActionClientCapabilitiesResolveSupport.fromJson,
);
CodeActionClientCapabilitiesResolveSupport({
required this.properties,
});
static CodeActionClientCapabilitiesResolveSupport fromJson(
Map<String, Object?> json) {
final propertiesJson = json['properties'];
final properties = (propertiesJson as List<Object?>)
.map((item) => item as String)
.toList();
return CodeActionClientCapabilitiesResolveSupport(
properties: properties,
);
}
/// The properties that a client can resolve lazily.
final List<String> properties;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['properties'] = properties;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
return _canParseListString(obj, reporter, 'properties',
allowsUndefined: false, allowsNull: false);
} else {
reporter.reportError(
'must be of type CodeActionClientCapabilitiesResolveSupport');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CodeActionClientCapabilitiesResolveSupport &&
other.runtimeType == CodeActionClientCapabilitiesResolveSupport &&
listEqual(properties, other.properties, (String a, String b) => a == b);
}
@override
int get hashCode => lspHashCode(properties);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// Contains additional diagnostic information about the context in which a code
/// action is run.
class CodeActionContext implements ToJsonable {
static const jsonHandler = LspJsonHandler(
CodeActionContext.canParse,
CodeActionContext.fromJson,
);
CodeActionContext({
required this.diagnostics,
this.only,
this.triggerKind,
});
static CodeActionContext fromJson(Map<String, Object?> json) {
final diagnosticsJson = json['diagnostics'];
final diagnostics = (diagnosticsJson as List<Object?>)
.map((item) => Diagnostic.fromJson(item as Map<String, Object?>))
.toList();
final onlyJson = json['only'];
final only = (onlyJson as List<Object?>?)
?.map((item) => CodeActionKind.fromJson(item as String))
.toList();
final triggerKindJson = json['triggerKind'];
final triggerKind = triggerKindJson != null
? CodeActionTriggerKind.fromJson(triggerKindJson as int)
: null;
return CodeActionContext(
diagnostics: diagnostics,
only: only,
triggerKind: triggerKind,
);
}
/// An array of diagnostics known on the client side overlapping the range
/// provided to the `textDocument/codeAction` request. They are provided so
/// that the server knows which errors are currently presented to the user for
/// the given range. There is no guarantee that these accurately reflect the
/// error state of the resource. The primary parameter to compute code actions
/// is the provided range.
final List<Diagnostic> diagnostics;
/// Requested kind of actions to return.
///
/// Actions not of this kind are filtered out by the client before being
/// shown. So servers can omit computing them.
final List<CodeActionKind>? only;
/// The reason why code actions were requested.
///
/// @since 3.17.0
final CodeActionTriggerKind? triggerKind;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['diagnostics'] = diagnostics.map((item) => item.toJson()).toList();
if (only != null) {
result['only'] = only?.map((item) => item.toJson()).toList();
}
if (triggerKind != null) {
result['triggerKind'] = triggerKind?.toJson();
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseListDiagnostic(obj, reporter, 'diagnostics',
allowsUndefined: false, allowsNull: false)) {
return false;
}
if (!_canParseListCodeActionKind(obj, reporter, 'only',
allowsUndefined: true, allowsNull: false)) {
return false;
}
return _canParseCodeActionTriggerKind(obj, reporter, 'triggerKind',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type CodeActionContext');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CodeActionContext &&
other.runtimeType == CodeActionContext &&
listEqual(diagnostics, other.diagnostics,
(Diagnostic a, Diagnostic b) => a == b) &&
listEqual(
only, other.only, (CodeActionKind a, CodeActionKind b) => a == b) &&
triggerKind == other.triggerKind;
}
@override
int get hashCode => Object.hash(
lspHashCode(diagnostics),
lspHashCode(only),
triggerKind,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
class CodeActionDisabled implements ToJsonable {
static const jsonHandler = LspJsonHandler(
CodeActionDisabled.canParse,
CodeActionDisabled.fromJson,
);
CodeActionDisabled({
required this.reason,
});
static CodeActionDisabled fromJson(Map<String, Object?> json) {
final reasonJson = json['reason'];
final reason = reasonJson as String;
return CodeActionDisabled(
reason: reason,
);
}
/// Human readable description of why the code action is currently disabled.
///
/// This is displayed in the code actions UI.
final String reason;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['reason'] = reason;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
return _canParseString(obj, reporter, 'reason',
allowsUndefined: false, allowsNull: false);
} else {
reporter.reportError('must be of type CodeActionDisabled');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CodeActionDisabled &&
other.runtimeType == CodeActionDisabled &&
reason == other.reason;
}
@override
int get hashCode => reason.hashCode;
@override
String toString() => jsonEncoder.convert(toJson());
}
/// A set of predefined code action kinds
class CodeActionKind implements ToJsonable {
const CodeActionKind(this._value);
const CodeActionKind.fromJson(this._value);
final String _value;
static bool canParse(Object? obj, LspJsonReporter reporter) => obj is String;
/// Empty kind.
static const Empty = CodeActionKind('');
/// Base kind for quickfix actions: 'quickfix'
static const QuickFix = CodeActionKind('quickfix');
/// Base kind for refactoring actions: 'refactor'
static const Refactor = CodeActionKind('refactor');
/// Base kind for refactoring extraction actions: 'refactor.extract'
///
/// Example extract actions:
///
/// - Extract method
/// - Extract function
/// - Extract variable
/// - Extract interface from class
/// - ...
static const RefactorExtract = CodeActionKind('refactor.extract');
/// Base kind for refactoring inline actions: 'refactor.inline'
///
/// Example inline actions:
///
/// - Inline function
/// - Inline variable
/// - Inline constant
/// - ...
static const RefactorInline = CodeActionKind('refactor.inline');
/// Base kind for refactoring rewrite actions: 'refactor.rewrite'
///
/// Example rewrite actions:
///
/// - Convert JavaScript function to class
/// - Add or remove parameter
/// - Encapsulate field
/// - Make method static
/// - Move method to base class
/// - ...
static const RefactorRewrite = CodeActionKind('refactor.rewrite');
/// Base kind for source actions: `source`
///
/// Source code actions apply to the entire file.
static const Source = CodeActionKind('source');
/// Base kind for auto-fix source actions: `source.fixAll`.
///
/// Fix all actions automatically fix errors that have a clear fix that do not
/// require user input. They should not suppress errors or perform unsafe
/// fixes such as generating new types or classes.
///
/// @since 3.15.0
static const SourceFixAll = CodeActionKind('source.fixAll');
/// Base kind for an organize imports source action: `source.organizeImports`
static const SourceOrganizeImports = CodeActionKind('source.organizeImports');
@override
Object toJson() => _value;
@override
String toString() => _value.toString();
@override
int get hashCode => _value.hashCode;
@override
bool operator ==(Object other) =>
other is CodeActionKind && other._value == _value;
}
class CodeActionLiteralSupportCodeActionKind implements ToJsonable {
static const jsonHandler = LspJsonHandler(
CodeActionLiteralSupportCodeActionKind.canParse,
CodeActionLiteralSupportCodeActionKind.fromJson,
);
CodeActionLiteralSupportCodeActionKind({
required this.valueSet,
});
static CodeActionLiteralSupportCodeActionKind fromJson(
Map<String, Object?> json) {
final valueSetJson = json['valueSet'];
final valueSet = (valueSetJson as List<Object?>)
.map((item) => CodeActionKind.fromJson(item as String))
.toList();
return CodeActionLiteralSupportCodeActionKind(
valueSet: valueSet,
);
}
/// The code action kind values the client supports. When this property exists
/// the client also guarantees that it will handle values outside its set
/// gracefully and falls back to a default value when unknown.
final List<CodeActionKind> valueSet;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['valueSet'] = valueSet.map((item) => item.toJson()).toList();
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
return _canParseListCodeActionKind(obj, reporter, 'valueSet',
allowsUndefined: false, allowsNull: false);
} else {
reporter.reportError(
'must be of type CodeActionLiteralSupportCodeActionKind');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CodeActionLiteralSupportCodeActionKind &&
other.runtimeType == CodeActionLiteralSupportCodeActionKind &&
listEqual(valueSet, other.valueSet,
(CodeActionKind a, CodeActionKind b) => a == b);
}
@override
int get hashCode => lspHashCode(valueSet);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// Provider options for a CodeActionRequest.
class CodeActionOptions implements WorkDoneProgressOptions, ToJsonable {
static const jsonHandler = LspJsonHandler(
CodeActionOptions.canParse,
CodeActionOptions.fromJson,
);
CodeActionOptions({
this.codeActionKinds,
this.resolveProvider,
this.workDoneProgress,
});
static CodeActionOptions fromJson(Map<String, Object?> json) {
if (CodeActionRegistrationOptions.canParse(json, nullLspJsonReporter)) {
return CodeActionRegistrationOptions.fromJson(json);
}
final codeActionKindsJson = json['codeActionKinds'];
final codeActionKinds = (codeActionKindsJson as List<Object?>?)
?.map((item) => CodeActionKind.fromJson(item as String))
.toList();
final resolveProviderJson = json['resolveProvider'];
final resolveProvider = resolveProviderJson as bool?;
final workDoneProgressJson = json['workDoneProgress'];
final workDoneProgress = workDoneProgressJson as bool?;
return CodeActionOptions(
codeActionKinds: codeActionKinds,
resolveProvider: resolveProvider,
workDoneProgress: workDoneProgress,
);
}
/// CodeActionKinds that this server may return.
///
/// The list of kinds may be generic, such as `CodeActionKind.Refactor`, or
/// the server may list out every specific kind they provide.
final List<CodeActionKind>? codeActionKinds;
/// The server provides support to resolve additional information for a code
/// action.
///
/// @since 3.16.0
final bool? resolveProvider;
@override
final bool? workDoneProgress;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
if (codeActionKinds != null) {
result['codeActionKinds'] =
codeActionKinds?.map((item) => item.toJson()).toList();
}
if (resolveProvider != null) {
result['resolveProvider'] = resolveProvider;
}
if (workDoneProgress != null) {
result['workDoneProgress'] = workDoneProgress;
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseListCodeActionKind(obj, reporter, 'codeActionKinds',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseBool(obj, reporter, 'resolveProvider',
allowsUndefined: true, allowsNull: false)) {
return false;
}
return _canParseBool(obj, reporter, 'workDoneProgress',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type CodeActionOptions');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CodeActionOptions &&
other.runtimeType == CodeActionOptions &&
listEqual(codeActionKinds, other.codeActionKinds,
(CodeActionKind a, CodeActionKind b) => a == b) &&
resolveProvider == other.resolveProvider &&
workDoneProgress == other.workDoneProgress;
}
@override
int get hashCode => Object.hash(
lspHashCode(codeActionKinds),
resolveProvider,
workDoneProgress,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// The parameters of a CodeActionRequest.
class CodeActionParams
implements PartialResultParams, WorkDoneProgressParams, ToJsonable {
static const jsonHandler = LspJsonHandler(
CodeActionParams.canParse,
CodeActionParams.fromJson,
);
CodeActionParams({
required this.context,
this.partialResultToken,
required this.range,
required this.textDocument,
this.workDoneToken,
});
static CodeActionParams fromJson(Map<String, Object?> json) {
final contextJson = json['context'];
final context =
CodeActionContext.fromJson(contextJson as Map<String, Object?>);
final partialResultTokenJson = json['partialResultToken'];
final partialResultToken = partialResultTokenJson == null
? null
: _eitherIntString(partialResultTokenJson);
final rangeJson = json['range'];
final range = Range.fromJson(rangeJson as Map<String, Object?>);
final textDocumentJson = json['textDocument'];
final textDocument = TextDocumentIdentifier.fromJson(
textDocumentJson as Map<String, Object?>);
final workDoneTokenJson = json['workDoneToken'];
final workDoneToken =
workDoneTokenJson == null ? null : _eitherIntString(workDoneTokenJson);
return CodeActionParams(
context: context,
partialResultToken: partialResultToken,
range: range,
textDocument: textDocument,
workDoneToken: workDoneToken,
);
}
/// Context carrying additional information.
final CodeActionContext context;
/// An optional token that a server can use to report partial results (e.g.
/// streaming) to the client.
@override
final ProgressToken? partialResultToken;
/// The range for which the command was invoked.
final Range range;
/// The document in which the command was invoked.
final TextDocumentIdentifier textDocument;
/// An optional token that a server can use to report work done progress.
@override
final ProgressToken? workDoneToken;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['context'] = context.toJson();
if (partialResultToken != null) {
result['partialResultToken'] = partialResultToken;
}
result['range'] = range.toJson();
result['textDocument'] = textDocument.toJson();
if (workDoneToken != null) {
result['workDoneToken'] = workDoneToken;
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseCodeActionContext(obj, reporter, 'context',
allowsUndefined: false, allowsNull: false)) {
return false;
}
if (!_canParseIntString(obj, reporter, 'partialResultToken',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseRange(obj, reporter, 'range',
allowsUndefined: false, allowsNull: false)) {
return false;
}
if (!_canParseTextDocumentIdentifier(obj, reporter, 'textDocument',
allowsUndefined: false, allowsNull: false)) {
return false;
}
return _canParseIntString(obj, reporter, 'workDoneToken',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type CodeActionParams');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CodeActionParams &&
other.runtimeType == CodeActionParams &&
context == other.context &&
partialResultToken == other.partialResultToken &&
range == other.range &&
textDocument == other.textDocument &&
workDoneToken == other.workDoneToken;
}
@override
int get hashCode => Object.hash(
context,
partialResultToken,
range,
textDocument,
workDoneToken,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// Registration options for a CodeActionRequest.
class CodeActionRegistrationOptions
implements CodeActionOptions, TextDocumentRegistrationOptions, ToJsonable {
static const jsonHandler = LspJsonHandler(
CodeActionRegistrationOptions.canParse,
CodeActionRegistrationOptions.fromJson,
);
CodeActionRegistrationOptions({
this.codeActionKinds,
this.documentSelector,
this.resolveProvider,
this.workDoneProgress,
});
static CodeActionRegistrationOptions fromJson(Map<String, Object?> json) {
final codeActionKindsJson = json['codeActionKinds'];
final codeActionKinds = (codeActionKindsJson as List<Object?>?)
?.map((item) => CodeActionKind.fromJson(item as String))
.toList();
final documentSelectorJson = json['documentSelector'];
final documentSelector = (documentSelectorJson as List<Object?>?)
?.map((item) =>
TextDocumentFilterWithScheme.fromJson(item as Map<String, Object?>))
.toList();
final resolveProviderJson = json['resolveProvider'];
final resolveProvider = resolveProviderJson as bool?;
final workDoneProgressJson = json['workDoneProgress'];
final workDoneProgress = workDoneProgressJson as bool?;
return CodeActionRegistrationOptions(
codeActionKinds: codeActionKinds,
documentSelector: documentSelector,
resolveProvider: resolveProvider,
workDoneProgress: workDoneProgress,
);
}
/// CodeActionKinds that this server may return.
///
/// The list of kinds may be generic, such as `CodeActionKind.Refactor`, or
/// the server may list out every specific kind they provide.
@override
final List<CodeActionKind>? codeActionKinds;
/// A document selector to identify the scope of the registration. If set to
/// null the document selector provided on the client side will be used.
@override
final List<TextDocumentFilterWithScheme>? documentSelector;
/// The server provides support to resolve additional information for a code
/// action.
///
/// @since 3.16.0
@override
final bool? resolveProvider;
@override
final bool? workDoneProgress;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
if (codeActionKinds != null) {
result['codeActionKinds'] =
codeActionKinds?.map((item) => item.toJson()).toList();
}
result['documentSelector'] = documentSelector;
if (resolveProvider != null) {
result['resolveProvider'] = resolveProvider;
}
if (workDoneProgress != null) {
result['workDoneProgress'] = workDoneProgress;
}
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
if (!_canParseListCodeActionKind(obj, reporter, 'codeActionKinds',
allowsUndefined: true, allowsNull: false)) {
return false;
}
if (!_canParseListTextDocumentFilterWithScheme(
obj, reporter, 'documentSelector',
allowsUndefined: false, allowsNull: true)) {
return false;
}
if (!_canParseBool(obj, reporter, 'resolveProvider',
allowsUndefined: true, allowsNull: false)) {
return false;
}
return _canParseBool(obj, reporter, 'workDoneProgress',
allowsUndefined: true, allowsNull: false);
} else {
reporter.reportError('must be of type CodeActionRegistrationOptions');
return false;
}
}
@override
bool operator ==(Object other) {
return other is CodeActionRegistrationOptions &&
other.runtimeType == CodeActionRegistrationOptions &&
listEqual(codeActionKinds, other.codeActionKinds,
(CodeActionKind a, CodeActionKind b) => a == b) &&
listEqual(
documentSelector,
other.documentSelector,
(TextDocumentFilterWithScheme a, TextDocumentFilterWithScheme b) =>
a == b) &&
resolveProvider == other.resolveProvider &&
workDoneProgress == other.workDoneProgress;
}
@override
int get hashCode => Object.hash(
lspHashCode(codeActionKinds),
lspHashCode(documentSelector),
resolveProvider,
workDoneProgress,
);
@override
String toString() => jsonEncoder.convert(toJson());
}
/// The reason why code actions were requested.
///
/// @since 3.17.0
class CodeActionTriggerKind implements ToJsonable {
const CodeActionTriggerKind(this._value);
const CodeActionTriggerKind.fromJson(this._value);
final int _value;
static bool canParse(Object? obj, LspJsonReporter reporter) => obj is int;
/// Code actions were requested automatically.
///
/// This typically happens when current selection in a file changes, but can
/// also be triggered when file content changes.
static const Automatic = CodeActionTriggerKind(2);
/// Code actions were explicitly requested by the user or by an extension.
static const Invoked = CodeActionTriggerKind(1);
@override
Object toJson() => _value;
@override
String toString() => _value.toString();
@override
int get hashCode => _value.hashCode;
@override
bool operator ==(Object other) =>
other is CodeActionTriggerKind && other._value == _value;
}
/// Structure to capture a description for an error code.
///
/// @since 3.16.0
class CodeDescription implements ToJsonable {
static const jsonHandler = LspJsonHandler(
CodeDescription.canParse,
CodeDescription.fromJson,
);
CodeDescription({
required this.href,
});
static CodeDescription fromJson(Map<String, Object?> json) {
final hrefJson = json['href'];
final href = hrefJson as String;
return CodeDescription(
href: href,
);
}
/// An URI to open with more information about the diagnostic error.
final LspUri href;
@override
Map<String, Object?> toJson() {
var result = <String, Object?>{};
result['href'] = href;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
if (obj is Map<String, Object?>) {
return _canParseString(obj, reporter, 'href',
allowsUndefined: false, allowsNull: false);
} else {
reporter.reportError('must be of type CodeDescription');
return false;
}
}