import { coalesce, asArray, isNonEmptyArray } from '../../../base/common/arrays.js';
import { encodeBase64, VSBuffer } from '../../../base/common/buffer.js';
import { UriList } from '../../../base/common/dataTransfer.js';
import { createSingleCallFunction } from '../../../base/common/functional.js';
import { parseHrefAndDimensions, isMarkdownString } from '../../../base/common/htmlContent.js';
import { ResourceSet, ResourceMap } from '../../../base/common/map.js';
import marked from 'vscode-marked';
import { parse, revive } from '../../../base/common/marshalling.js';
import { Mimes } from '../../../base/common/mime.js';
import { cloneAndChange } from '../../../base/common/objects.js';
import { basename } from '../../../base/common/resources.js';
import { isString, isNumber, isUndefinedOrNull, isEmptyObject } from '../../../base/common/types.js';
import { URI, isUriComponents } from '../../../base/common/uri.js';
import { Range as Range$2 } from '../../../editor/common/core/range.js';
import { Command, FoldingRangeKind as FoldingRangeKind$2 } from '../../../editor/common/languages.js';
import { MarkerSeverity } from '../../../platform/markers/common/markers.js';
import { getPrivateApiFor } from './extHostTestingPrivateApi.js';
import { DEFAULT_EDITOR_ASSOCIATION } from '../../common/editor.js';
import { CellKind, NotebookCellExecutionState as NotebookCellExecutionState$1 } from '../../contrib/notebook/common/notebookCommon.js';
import { TestId } from '../../contrib/testing/common/testId.js';
import { namespaceTestTag, denamespaceTestTag } from '../../contrib/testing/common/testTypes.js';
import { SIDE_GROUP, ACTIVE_GROUP } from '../../services/editor/common/editorService.js';
import { checkProposedApiEnabled } from '../../services/extensions/common/extensions.js';
import { Position as Position$1, Selection as Selection$1, Range as Range$1, Diagnostic as Diagnostic$1, ViewColumn as ViewColumn$1, MarkdownString as MarkdownString$1, WorkspaceEdit as WorkspaceEdit$1, SnippetTextEdit, SnippetString, TextEdit as TextEdit$1, SymbolKind as SymbolKind$1, SymbolInformation, CallHierarchyItem as CallHierarchyItem$1, CallHierarchyIncomingCall as CallHierarchyIncomingCall$1, CallHierarchyOutgoingCall as CallHierarchyOutgoingCall$1, Location as Location$1, InlineValueText, InlineValueVariableLookup, InlineValueEvaluatableExpression, InlineValueContext as InlineValueContext$1, CompletionItem as CompletionItem$1, InlayHint as InlayHint$1, DocumentLink as DocumentLink$1, ColorPresentation as ColorPresentation$1, Color as Color$1, NotebookCellOutputItem as NotebookCellOutputItem$1, NotebookCellOutput as NotebookCellOutput$1, TestTag as TestTag$1, TypeHierarchyItem as TypeHierarchyItem$1, DiagnosticRelatedInformation as DiagnosticRelatedInformation$1, DiagnosticSeverity as DiagnosticSeverity$1, Hover as Hover$1, DocumentHighlight as DocumentHighlight$1, InlayHintLabelPart as InlayHintLabelPart$1, FoldingRangeKind as FoldingRangeKind$1, NotebookCellData as NotebookCellData$1, DiagnosticTag as DiagnosticTag$1, SymbolTag as SymbolTag$1, CompletionItemTag as CompletionItemTag$1, CompletionItemKind as CompletionItemKind$1, EndOfLine as EndOfLine$1, RelativePattern, NotebookRange as NotebookRange$1, NotebookCellKind as NotebookCellKind$1, DataTransfer as DataTransfer$1, StandardTokenType, TextDocumentSaveReason as TextDocumentSaveReason$1, TextEditorLineNumbersStyle as TextEditorLineNumbersStyle$1, ProgressLocation as ProgressLocation$1, NotebookCellExecutionState as NotebookCellExecutionState$2, TestMessage as TestMessage$1, InternalFileDataTransferItem, DataTransferFile, InternalDataTransferItem, LanguageModelAssistantMessage, LanguageModelUserMessage, LanguageModelSystemMessage, InteractiveEditorResponseFeedbackKind as InteractiveEditorResponseFeedbackKind$1, ChatResponseMarkdownPart as ChatResponseMarkdownPart$1, ChatResponseAnchorPart as ChatResponseAnchorPart$1, ChatResponseReferencePart as ChatResponseReferencePart$1, ChatResponseProgressPart as ChatResponseProgressPart$1, ChatResponseFileTreePart, DocumentSymbol as DocumentSymbol$1, EvaluatableExpression as EvaluatableExpression$1, MultiDocumentHighlight as MultiDocumentHighlight$1, SelectionRange as SelectionRange$1, NotebookData as NotebookData$1, NotebookCellStatusBarAlignment, NotebookRendererScript as NotebookRendererScript$1, CodeActionTriggerKind as CodeActionTriggerKind$1, ChatVariableLevel as ChatVariableLevel$1, ChatResponseCommandButtonPart as ChatResponseCommandButtonPart$1, DecorationRangeBehavior as DecorationRangeBehavior$1, CompletionTriggerKind as CompletionTriggerKind$1 } from './extHostTypes.js';
var Selection;
( (function(Selection) {
    function to(selection) {
        const { selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn } = selection;
        const start = new Position$1(selectionStartLineNumber - 1, selectionStartColumn - 1);
        const end = new Position$1(positionLineNumber - 1, positionColumn - 1);
        return new Selection$1(start, end);
    }
    Selection.to = to;
    function from(selection) {
        const { anchor, active } = selection;
        return {
            selectionStartLineNumber: anchor.line + 1,
            selectionStartColumn: anchor.character + 1,
            positionLineNumber: active.line + 1,
            positionColumn: active.character + 1
        };
    }
    Selection.from = from;
})(Selection || (Selection = {})));
var Range;
( (function(Range) {
    function from(range) {
        if (!range) {
            return undefined;
        }
        const { start, end } = range;
        return {
            startLineNumber: start.line + 1,
            startColumn: start.character + 1,
            endLineNumber: end.line + 1,
            endColumn: end.character + 1
        };
    }
    Range.from = from;
    function to(range) {
        if (!range) {
            return undefined;
        }
        const { startLineNumber, startColumn, endLineNumber, endColumn } = range;
        return new Range$1(startLineNumber - 1, startColumn - 1, endLineNumber - 1, endColumn - 1);
    }
    Range.to = to;
})(Range || (Range = {})));
var Location;
( (function(Location) {
    function from(location) {
        return {
            uri: location.uri,
            range: Range.from(location.range)
        };
    }
    Location.from = from;
    function to(location) {
        return new Location$1(URI.revive(location.uri), Range.to(location.range));
    }
    Location.to = to;
})(Location || (Location = {})));
var TokenType;
( (function(TokenType) {
    function to(type) {
        switch (type) {
            case 1 : return StandardTokenType.Comment;
            case 0 : return StandardTokenType.Other;
            case 3 : return StandardTokenType.RegEx;
            case 2 : return StandardTokenType.String;
        }
    }
    TokenType.to = to;
})(TokenType || (TokenType = {})));
var Position;
( (function(Position) {
    function to(position) {
        return new Position$1(position.lineNumber - 1, position.column - 1);
    }
    Position.to = to;
    function from(position) {
        return { lineNumber: position.line + 1, column: position.character + 1 };
    }
    Position.from = from;
})(Position || (Position = {})));
var DocumentSelector;
( (function(DocumentSelector) {
    function from(value, uriTransformer, extension) {
        return coalesce(( asArray(value).map(sel => _doTransformDocumentSelector(sel, uriTransformer, extension))));
    }
    DocumentSelector.from = from;
    function _doTransformDocumentSelector(selector, uriTransformer, extension) {
        if (typeof selector === 'string') {
            return {
                $serialized: true,
                language: selector,
                isBuiltin: extension?.isBuiltin,
            };
        }
        if (selector) {
            return {
                $serialized: true,
                language: selector.language,
                scheme: _transformScheme(selector.scheme, uriTransformer),
                pattern: GlobPattern.from(selector.pattern) ?? undefined,
                exclusive: selector.exclusive,
                notebookType: selector.notebookType,
                isBuiltin: extension?.isBuiltin
            };
        }
        return undefined;
    }
    function _transformScheme(scheme, uriTransformer) {
        if (uriTransformer && typeof scheme === 'string') {
            return uriTransformer.transformOutgoingScheme(scheme);
        }
        return scheme;
    }
})(DocumentSelector || (DocumentSelector = {})));
var DiagnosticTag;
( (function(DiagnosticTag) {
    function from(value) {
        switch (value) {
            case DiagnosticTag$1.Unnecessary:
                return 1 ;
            case DiagnosticTag$1.Deprecated:
                return 2 ;
        }
        return undefined;
    }
    DiagnosticTag.from = from;
    function to(value) {
        switch (value) {
            case 1 :
                return DiagnosticTag$1.Unnecessary;
            case 2 :
                return DiagnosticTag$1.Deprecated;
            default:
                return undefined;
        }
    }
    DiagnosticTag.to = to;
})(DiagnosticTag || (DiagnosticTag = {})));
var Diagnostic;
( (function(Diagnostic) {
    function from(value) {
        let code;
        if (value.code) {
            if (isString(value.code) || isNumber(value.code)) {
                code = String(value.code);
            }
            else {
                code = {
                    value: String(value.code.value),
                    target: value.code.target,
                };
            }
        }
        return {
            ...Range.from(value.range),
            message: value.message,
            source: value.source,
            code,
            severity: DiagnosticSeverity.from(value.severity),
            relatedInformation: value.relatedInformation && ( value.relatedInformation.map(DiagnosticRelatedInformation.from)),
            tags: Array.isArray(value.tags) ? coalesce(( value.tags.map(DiagnosticTag.from))) : undefined,
        };
    }
    Diagnostic.from = from;
    function to(value) {
        const res = new Diagnostic$1(Range.to(value), value.message, DiagnosticSeverity.to(value.severity));
        res.source = value.source;
        res.code = isString(value.code) ? value.code : value.code?.value;
        res.relatedInformation = value.relatedInformation && ( value.relatedInformation.map(DiagnosticRelatedInformation.to));
        res.tags = value.tags && coalesce(( value.tags.map(DiagnosticTag.to)));
        return res;
    }
    Diagnostic.to = to;
})(Diagnostic || (Diagnostic = {})));
var DiagnosticRelatedInformation;
( (function(DiagnosticRelatedInformation) {
    function from(value) {
        return {
            ...Range.from(value.location.range),
            message: value.message,
            resource: value.location.uri
        };
    }
    DiagnosticRelatedInformation.from = from;
    function to(value) {
        return new DiagnosticRelatedInformation$1(new Location$1(value.resource, Range.to(value)), value.message);
    }
    DiagnosticRelatedInformation.to = to;
})(DiagnosticRelatedInformation || (DiagnosticRelatedInformation = {})));
var DiagnosticSeverity;
( (function(DiagnosticSeverity) {
    function from(value) {
        switch (value) {
            case DiagnosticSeverity$1.Error:
                return MarkerSeverity.Error;
            case DiagnosticSeverity$1.Warning:
                return MarkerSeverity.Warning;
            case DiagnosticSeverity$1.Information:
                return MarkerSeverity.Info;
            case DiagnosticSeverity$1.Hint:
                return MarkerSeverity.Hint;
        }
        return MarkerSeverity.Error;
    }
    DiagnosticSeverity.from = from;
    function to(value) {
        switch (value) {
            case MarkerSeverity.Info:
                return DiagnosticSeverity$1.Information;
            case MarkerSeverity.Warning:
                return DiagnosticSeverity$1.Warning;
            case MarkerSeverity.Error:
                return DiagnosticSeverity$1.Error;
            case MarkerSeverity.Hint:
                return DiagnosticSeverity$1.Hint;
            default:
                return DiagnosticSeverity$1.Error;
        }
    }
    DiagnosticSeverity.to = to;
})(DiagnosticSeverity || (DiagnosticSeverity = {})));
var ViewColumn;
( (function(ViewColumn) {
    function from(column) {
        if (typeof column === 'number' && column >= ViewColumn$1.One) {
            return column - 1;
        }
        if (column === ViewColumn$1.Beside) {
            return SIDE_GROUP;
        }
        return ACTIVE_GROUP;
    }
    ViewColumn.from = from;
    function to(position) {
        if (typeof position === 'number' && position >= 0) {
            return position + 1;
        }
        throw new Error(`invalid 'EditorGroupColumn'`);
    }
    ViewColumn.to = to;
})(ViewColumn || (ViewColumn = {})));
function isDecorationOptions(something) {
    return (typeof something.range !== 'undefined');
}
function isDecorationOptionsArr(something) {
    if (something.length === 0) {
        return true;
    }
    return isDecorationOptions(something[0]) ? true : false;
}
var MarkdownString;
( (function(MarkdownString) {
    function fromMany(markup) {
        return ( markup.map(MarkdownString.from));
    }
    MarkdownString.fromMany = fromMany;
    function isCodeblock(thing) {
        return thing && typeof thing === 'object'
            && typeof thing.language === 'string'
            && typeof thing.value === 'string';
    }
    function from(markup) {
        let res;
        if (isCodeblock(markup)) {
            const { language, value } = markup;
            res = { value: '```' + language + '\n' + value + '\n```\n' };
        }
        else if (MarkdownString$1.isMarkdownString(markup)) {
            res = { value: markup.value, isTrusted: markup.isTrusted, supportThemeIcons: markup.supportThemeIcons, supportHtml: markup.supportHtml, baseUri: markup.baseUri };
        }
        else if (typeof markup === 'string') {
            res = { value: markup };
        }
        else {
            res = { value: '' };
        }
        const resUris = Object.create(null);
        res.uris = resUris;
        const collectUri = (href) => {
            try {
                let uri = ( URI.parse(href, true));
                uri = uri.with({ query: _uriMassage(uri.query, resUris) });
                resUris[href] = uri;
            }
            catch (e) {
            }
            return '';
        };
        const renderer = new marked.Renderer();
        renderer.link = collectUri;
        renderer.image = href => typeof href === 'string' ? collectUri(parseHrefAndDimensions(href).href) : '';
        marked(res.value, { renderer });
        return res;
    }
    MarkdownString.from = from;
    function _uriMassage(part, bucket) {
        if (!part) {
            return part;
        }
        let data;
        try {
            data = parse(part);
        }
        catch (e) {
        }
        if (!data) {
            return part;
        }
        let changed = false;
        data = cloneAndChange(data, value => {
            if (URI.isUri(value)) {
                const key = `__uri_${( Math.random().toString(16)).slice(2, 8)}`;
                bucket[key] = value;
                changed = true;
                return key;
            }
            else {
                return undefined;
            }
        });
        if (!changed) {
            return part;
        }
        return JSON.stringify(data);
    }
    function to(value) {
        const result = new MarkdownString$1(value.value, value.supportThemeIcons);
        result.isTrusted = value.isTrusted;
        result.supportHtml = value.supportHtml;
        result.baseUri = value.baseUri ? ( URI.from(value.baseUri)) : undefined;
        return result;
    }
    MarkdownString.to = to;
    function fromStrict(value) {
        if (!value) {
            return undefined;
        }
        return typeof value === 'string' ? value : MarkdownString.from(value);
    }
    MarkdownString.fromStrict = fromStrict;
})(MarkdownString || (MarkdownString = {})));
function fromRangeOrRangeWithMessage(ranges) {
    if (isDecorationOptionsArr(ranges)) {
        return ( ranges.map((r) => {
            return {
                range: Range.from(r.range),
                hoverMessage: Array.isArray(r.hoverMessage)
                    ? MarkdownString.fromMany(r.hoverMessage)
                    : (r.hoverMessage ? MarkdownString.from(r.hoverMessage) : undefined),
                renderOptions:  r.renderOptions
            };
        }));
    }
    else {
        return ( ranges.map((r) => {
            return {
                range: Range.from(r)
            };
        }));
    }
}
function pathOrURIToURI(value) {
    if (typeof value === 'undefined') {
        return value;
    }
    if (typeof value === 'string') {
        return URI.file(value);
    }
    else {
        return value;
    }
}
var ThemableDecorationAttachmentRenderOptions;
( (function(ThemableDecorationAttachmentRenderOptions) {
    function from(options) {
        if (typeof options === 'undefined') {
            return options;
        }
        return {
            contentText: options.contentText,
            contentIconPath: options.contentIconPath ? pathOrURIToURI(options.contentIconPath) : undefined,
            border: options.border,
            borderColor: options.borderColor,
            fontStyle: options.fontStyle,
            fontWeight: options.fontWeight,
            textDecoration: options.textDecoration,
            color: options.color,
            backgroundColor: options.backgroundColor,
            margin: options.margin,
            width: options.width,
            height: options.height,
        };
    }
    ThemableDecorationAttachmentRenderOptions.from = from;
})(
    ThemableDecorationAttachmentRenderOptions || (ThemableDecorationAttachmentRenderOptions = {})
));
var ThemableDecorationRenderOptions;
( (function(ThemableDecorationRenderOptions) {
    function from(options) {
        if (typeof options === 'undefined') {
            return options;
        }
        return {
            backgroundColor: options.backgroundColor,
            outline: options.outline,
            outlineColor: options.outlineColor,
            outlineStyle: options.outlineStyle,
            outlineWidth: options.outlineWidth,
            border: options.border,
            borderColor: options.borderColor,
            borderRadius: options.borderRadius,
            borderSpacing: options.borderSpacing,
            borderStyle: options.borderStyle,
            borderWidth: options.borderWidth,
            fontStyle: options.fontStyle,
            fontWeight: options.fontWeight,
            textDecoration: options.textDecoration,
            cursor: options.cursor,
            color: options.color,
            opacity: options.opacity,
            letterSpacing: options.letterSpacing,
            gutterIconPath: options.gutterIconPath ? pathOrURIToURI(options.gutterIconPath) : undefined,
            gutterIconSize: options.gutterIconSize,
            overviewRulerColor: options.overviewRulerColor,
            before: options.before ? ThemableDecorationAttachmentRenderOptions.from(options.before) : undefined,
            after: options.after ? ThemableDecorationAttachmentRenderOptions.from(options.after) : undefined,
        };
    }
    ThemableDecorationRenderOptions.from = from;
})(ThemableDecorationRenderOptions || (ThemableDecorationRenderOptions = {})));
var DecorationRangeBehavior;
( (function(DecorationRangeBehavior) {
    function from(value) {
        if (typeof value === 'undefined') {
            return value;
        }
        switch (value) {
            case DecorationRangeBehavior$1.OpenOpen:
                return 0 ;
            case DecorationRangeBehavior$1.ClosedClosed:
                return 1 ;
            case DecorationRangeBehavior$1.OpenClosed:
                return 2 ;
            case DecorationRangeBehavior$1.ClosedOpen:
                return 3 ;
        }
    }
    DecorationRangeBehavior.from = from;
})(DecorationRangeBehavior || (DecorationRangeBehavior = {})));
var DecorationRenderOptions;
( (function(DecorationRenderOptions) {
    function from(options) {
        return {
            isWholeLine: options.isWholeLine,
            rangeBehavior: options.rangeBehavior ? DecorationRangeBehavior.from(options.rangeBehavior) : undefined,
            overviewRulerLane: options.overviewRulerLane,
            light: options.light ? ThemableDecorationRenderOptions.from(options.light) : undefined,
            dark: options.dark ? ThemableDecorationRenderOptions.from(options.dark) : undefined,
            backgroundColor: options.backgroundColor,
            outline: options.outline,
            outlineColor: options.outlineColor,
            outlineStyle: options.outlineStyle,
            outlineWidth: options.outlineWidth,
            border: options.border,
            borderColor: options.borderColor,
            borderRadius: options.borderRadius,
            borderSpacing: options.borderSpacing,
            borderStyle: options.borderStyle,
            borderWidth: options.borderWidth,
            fontStyle: options.fontStyle,
            fontWeight: options.fontWeight,
            textDecoration: options.textDecoration,
            cursor: options.cursor,
            color: options.color,
            opacity: options.opacity,
            letterSpacing: options.letterSpacing,
            gutterIconPath: options.gutterIconPath ? pathOrURIToURI(options.gutterIconPath) : undefined,
            gutterIconSize: options.gutterIconSize,
            overviewRulerColor: options.overviewRulerColor,
            before: options.before ? ThemableDecorationAttachmentRenderOptions.from(options.before) : undefined,
            after: options.after ? ThemableDecorationAttachmentRenderOptions.from(options.after) : undefined,
        };
    }
    DecorationRenderOptions.from = from;
})(DecorationRenderOptions || (DecorationRenderOptions = {})));
var TextEdit;
( (function(TextEdit) {
    function from(edit) {
        return {
            text: edit.newText,
            eol: edit.newEol && EndOfLine.from(edit.newEol),
            range: Range.from(edit.range)
        };
    }
    TextEdit.from = from;
    function to(edit) {
        const result = new TextEdit$1(Range.to(edit.range), edit.text);
        result.newEol = (typeof edit.eol === 'undefined' ? undefined : EndOfLine.to(edit.eol));
        return result;
    }
    TextEdit.to = to;
})(TextEdit || (TextEdit = {})));
var WorkspaceEdit;
( (function(WorkspaceEdit) {
    function from(value, versionInfo) {
        const result = {
            edits: []
        };
        if (value instanceof WorkspaceEdit$1) {
            const toCreate = ( new ResourceSet());
            for (const entry of value._allEntries()) {
                if (entry._type === 1  && URI.isUri(entry.to) && entry.from === undefined) {
                    toCreate.add(entry.to);
                }
            }
            for (const entry of value._allEntries()) {
                if (entry._type === 1 ) {
                    let contents;
                    if (entry.options?.contents) {
                        if (ArrayBuffer.isView(entry.options.contents)) {
                            contents = { type: 'base64', value: encodeBase64(VSBuffer.wrap(entry.options.contents)) };
                        }
                        else {
                            contents = { type: 'dataTransferItem', id: entry.options.contents._itemId };
                        }
                    }
                    result.edits.push({
                        oldResource: entry.from,
                        newResource: entry.to,
                        options: { ...entry.options, contents },
                        metadata: entry.metadata
                    });
                }
                else if (entry._type === 2 ) {
                    result.edits.push({
                        resource: entry.uri,
                        textEdit: TextEdit.from(entry.edit),
                        versionId: !( toCreate.has(entry.uri)) ? versionInfo?.getTextDocumentVersion(entry.uri) : undefined,
                        metadata: entry.metadata
                    });
                }
                else if (entry._type === 6 ) {
                    result.edits.push({
                        resource: entry.uri,
                        textEdit: {
                            range: Range.from(entry.range),
                            text: entry.edit.value,
                            insertAsSnippet: true
                        },
                        versionId: !( toCreate.has(entry.uri)) ? versionInfo?.getTextDocumentVersion(entry.uri) : undefined,
                        metadata: entry.metadata
                    });
                }
                else if (entry._type === 3 ) {
                    result.edits.push({
                        metadata: entry.metadata,
                        resource: entry.uri,
                        cellEdit: entry.edit,
                        notebookMetadata: entry.notebookMetadata,
                        notebookVersionId: versionInfo?.getNotebookDocumentVersion(entry.uri)
                    });
                }
                else if (entry._type === 5 ) {
                    result.edits.push({
                        metadata: entry.metadata,
                        resource: entry.uri,
                        notebookVersionId: versionInfo?.getNotebookDocumentVersion(entry.uri),
                        cellEdit: {
                            editType: 1 ,
                            index: entry.index,
                            count: entry.count,
                            cells: ( entry.cells.map(NotebookCellData.from))
                        }
                    });
                }
            }
        }
        return result;
    }
    WorkspaceEdit.from = from;
    function to(value) {
        const result = new WorkspaceEdit$1();
        const edits = ( new ResourceMap());
        for (const edit of value.edits) {
            if (edit.textEdit) {
                const item = edit;
                const uri = URI.revive(item.resource);
                const range = Range.to(item.textEdit.range);
                const text = item.textEdit.text;
                const isSnippet = item.textEdit.insertAsSnippet;
                let editOrSnippetTest;
                if (isSnippet) {
                    editOrSnippetTest = SnippetTextEdit.replace(range, new SnippetString(text));
                }
                else {
                    editOrSnippetTest = TextEdit$1.replace(range, text);
                }
                const array = edits.get(uri);
                if (!array) {
                    edits.set(uri, [editOrSnippetTest]);
                }
                else {
                    array.push(editOrSnippetTest);
                }
            }
            else {
                result.renameFile(URI.revive(edit.oldResource), URI.revive(edit.newResource), edit.options);
            }
        }
        for (const [uri, array] of edits) {
            result.set(uri, array);
        }
        return result;
    }
    WorkspaceEdit.to = to;
})(WorkspaceEdit || (WorkspaceEdit = {})));
var SymbolKind;
( (function(SymbolKind) {
    const _fromMapping = Object.create(null);
    _fromMapping[SymbolKind$1.File] = 0 ;
    _fromMapping[SymbolKind$1.Module] = 1 ;
    _fromMapping[SymbolKind$1.Namespace] = 2 ;
    _fromMapping[SymbolKind$1.Package] = 3 ;
    _fromMapping[SymbolKind$1.Class] = 4 ;
    _fromMapping[SymbolKind$1.Method] = 5 ;
    _fromMapping[SymbolKind$1.Property] = 6 ;
    _fromMapping[SymbolKind$1.Field] = 7 ;
    _fromMapping[SymbolKind$1.Constructor] = 8 ;
    _fromMapping[SymbolKind$1.Enum] = 9 ;
    _fromMapping[SymbolKind$1.Interface] = 10 ;
    _fromMapping[SymbolKind$1.Function] = 11 ;
    _fromMapping[SymbolKind$1.Variable] = 12 ;
    _fromMapping[SymbolKind$1.Constant] = 13 ;
    _fromMapping[SymbolKind$1.String] = 14 ;
    _fromMapping[SymbolKind$1.Number] = 15 ;
    _fromMapping[SymbolKind$1.Boolean] = 16 ;
    _fromMapping[SymbolKind$1.Array] = 17 ;
    _fromMapping[SymbolKind$1.Object] = 18 ;
    _fromMapping[SymbolKind$1.Key] = 19 ;
    _fromMapping[SymbolKind$1.Null] = 20 ;
    _fromMapping[SymbolKind$1.EnumMember] = 21 ;
    _fromMapping[SymbolKind$1.Struct] = 22 ;
    _fromMapping[SymbolKind$1.Event] = 23 ;
    _fromMapping[SymbolKind$1.Operator] = 24 ;
    _fromMapping[SymbolKind$1.TypeParameter] = 25 ;
    function from(kind) {
        return typeof _fromMapping[kind] === 'number' ? _fromMapping[kind] : 6 ;
    }
    SymbolKind.from = from;
    function to(kind) {
        for (const k in _fromMapping) {
            if (_fromMapping[k] === kind) {
                return Number(k);
            }
        }
        return SymbolKind$1.Property;
    }
    SymbolKind.to = to;
})(SymbolKind || (SymbolKind = {})));
var SymbolTag;
( (function(SymbolTag) {
    function from(kind) {
        switch (kind) {
            case SymbolTag$1.Deprecated: return 1 ;
        }
    }
    SymbolTag.from = from;
    function to(kind) {
        switch (kind) {
            case 1 : return SymbolTag$1.Deprecated;
        }
    }
    SymbolTag.to = to;
})(SymbolTag || (SymbolTag = {})));
var WorkspaceSymbol;
( (function(WorkspaceSymbol) {
    function from(info) {
        return {
            name: info.name,
            kind: SymbolKind.from(info.kind),
            tags: info.tags && ( info.tags.map(SymbolTag.from)),
            containerName: info.containerName,
            location: location.from(info.location)
        };
    }
    WorkspaceSymbol.from = from;
    function to(info) {
        const result = new SymbolInformation(info.name, SymbolKind.to(info.kind), info.containerName, location.to(info.location));
        result.tags = info.tags && ( info.tags.map(SymbolTag.to));
        return result;
    }
    WorkspaceSymbol.to = to;
})(WorkspaceSymbol || (WorkspaceSymbol = {})));
var DocumentSymbol;
( (function(DocumentSymbol) {
    function from(info) {
        const result = {
            name: info.name || '!!MISSING: name!!',
            detail: info.detail,
            range: Range.from(info.range),
            selectionRange: Range.from(info.selectionRange),
            kind: SymbolKind.from(info.kind),
            tags: info.tags?.map(SymbolTag.from) ?? []
        };
        if (info.children) {
            result.children = ( info.children.map(from));
        }
        return result;
    }
    DocumentSymbol.from = from;
    function to(info) {
        const result = new DocumentSymbol$1(info.name, info.detail, SymbolKind.to(info.kind), Range.to(info.range), Range.to(info.selectionRange));
        if (isNonEmptyArray(info.tags)) {
            result.tags = ( info.tags.map(SymbolTag.to));
        }
        if (info.children) {
            result.children = ( info.children.map(to));
        }
        return result;
    }
    DocumentSymbol.to = to;
})(DocumentSymbol || (DocumentSymbol = {})));
var CallHierarchyItem;
( (function(CallHierarchyItem) {
    function to(item) {
        const result = new CallHierarchyItem$1(SymbolKind.to(item.kind), item.name, item.detail || '', URI.revive(item.uri), Range.to(item.range), Range.to(item.selectionRange));
        result._sessionId = item._sessionId;
        result._itemId = item._itemId;
        return result;
    }
    CallHierarchyItem.to = to;
    function from(item, sessionId, itemId) {
        sessionId = sessionId ?? item._sessionId;
        itemId = itemId ?? item._itemId;
        if (sessionId === undefined || itemId === undefined) {
            throw new Error('invalid item');
        }
        return {
            _sessionId: sessionId,
            _itemId: itemId,
            name: item.name,
            detail: item.detail,
            kind: SymbolKind.from(item.kind),
            uri: item.uri,
            range: Range.from(item.range),
            selectionRange: Range.from(item.selectionRange),
            tags: item.tags?.map(SymbolTag.from)
        };
    }
    CallHierarchyItem.from = from;
})(CallHierarchyItem || (CallHierarchyItem = {})));
var CallHierarchyIncomingCall;
( (function(CallHierarchyIncomingCall) {
    function to(item) {
        return new CallHierarchyIncomingCall$1(CallHierarchyItem.to(item.from), ( item.fromRanges.map(r => Range.to(r))));
    }
    CallHierarchyIncomingCall.to = to;
})(CallHierarchyIncomingCall || (CallHierarchyIncomingCall = {})));
var CallHierarchyOutgoingCall;
( (function(CallHierarchyOutgoingCall) {
    function to(item) {
        return new CallHierarchyOutgoingCall$1(CallHierarchyItem.to(item.to), ( item.fromRanges.map(r => Range.to(r))));
    }
    CallHierarchyOutgoingCall.to = to;
})(CallHierarchyOutgoingCall || (CallHierarchyOutgoingCall = {})));
var location;
( (function(location) {
    function from(value) {
        return {
            range: value.range && Range.from(value.range),
            uri: value.uri
        };
    }
    location.from = from;
    function to(value) {
        return new Location$1(URI.revive(value.uri), Range.to(value.range));
    }
    location.to = to;
})(location || (location = {})));
var DefinitionLink;
( (function(DefinitionLink) {
    function from(value) {
        const definitionLink = value;
        const location = value;
        return {
            originSelectionRange: definitionLink.originSelectionRange
                ? Range.from(definitionLink.originSelectionRange)
                : undefined,
            uri: definitionLink.targetUri ? definitionLink.targetUri : location.uri,
            range: Range.from(definitionLink.targetRange ? definitionLink.targetRange : location.range),
            targetSelectionRange: definitionLink.targetSelectionRange
                ? Range.from(definitionLink.targetSelectionRange)
                : undefined,
        };
    }
    DefinitionLink.from = from;
    function to(value) {
        return {
            targetUri: URI.revive(value.uri),
            targetRange: Range.to(value.range),
            targetSelectionRange: value.targetSelectionRange
                ? Range.to(value.targetSelectionRange)
                : undefined,
            originSelectionRange: value.originSelectionRange
                ? Range.to(value.originSelectionRange)
                : undefined
        };
    }
    DefinitionLink.to = to;
})(DefinitionLink || (DefinitionLink = {})));
var Hover;
( (function(Hover) {
    function from(hover) {
        return {
            range: Range.from(hover.range),
            contents: MarkdownString.fromMany(hover.contents)
        };
    }
    Hover.from = from;
    function to(info) {
        return new Hover$1(( info.contents.map(MarkdownString.to)), Range.to(info.range));
    }
    Hover.to = to;
})(Hover || (Hover = {})));
var EvaluatableExpression;
( (function(EvaluatableExpression) {
    function from(expression) {
        return {
            range: Range.from(expression.range),
            expression: expression.expression
        };
    }
    EvaluatableExpression.from = from;
    function to(info) {
        return new EvaluatableExpression$1(Range.to(info.range), info.expression);
    }
    EvaluatableExpression.to = to;
})(EvaluatableExpression || (EvaluatableExpression = {})));
var InlineValue;
( (function(InlineValue) {
    function from(inlineValue) {
        if (inlineValue instanceof InlineValueText) {
            return {
                type: 'text',
                range: Range.from(inlineValue.range),
                text: inlineValue.text
            };
        }
        else if (inlineValue instanceof InlineValueVariableLookup) {
            return {
                type: 'variable',
                range: Range.from(inlineValue.range),
                variableName: inlineValue.variableName,
                caseSensitiveLookup: inlineValue.caseSensitiveLookup
            };
        }
        else if (inlineValue instanceof InlineValueEvaluatableExpression) {
            return {
                type: 'expression',
                range: Range.from(inlineValue.range),
                expression: inlineValue.expression
            };
        }
        else {
            throw new Error(`Unknown 'InlineValue' type`);
        }
    }
    InlineValue.from = from;
    function to(inlineValue) {
        switch (inlineValue.type) {
            case 'text':
                return {
                    range: Range.to(inlineValue.range),
                    text: inlineValue.text
                };
            case 'variable':
                return {
                    range: Range.to(inlineValue.range),
                    variableName: inlineValue.variableName,
                    caseSensitiveLookup: inlineValue.caseSensitiveLookup
                };
            case 'expression':
                return {
                    range: Range.to(inlineValue.range),
                    expression: inlineValue.expression
                };
        }
    }
    InlineValue.to = to;
})(InlineValue || (InlineValue = {})));
var InlineValueContext;
( (function(InlineValueContext) {
    function from(inlineValueContext) {
        return {
            frameId: inlineValueContext.frameId,
            stoppedLocation: Range.from(inlineValueContext.stoppedLocation)
        };
    }
    InlineValueContext.from = from;
    function to(inlineValueContext) {
        return new InlineValueContext$1(inlineValueContext.frameId, Range.to(inlineValueContext.stoppedLocation));
    }
    InlineValueContext.to = to;
})(InlineValueContext || (InlineValueContext = {})));
var DocumentHighlight;
( (function(DocumentHighlight) {
    function from(documentHighlight) {
        return {
            range: Range.from(documentHighlight.range),
            kind: documentHighlight.kind
        };
    }
    DocumentHighlight.from = from;
    function to(occurrence) {
        return new DocumentHighlight$1(Range.to(occurrence.range), occurrence.kind);
    }
    DocumentHighlight.to = to;
})(DocumentHighlight || (DocumentHighlight = {})));
var MultiDocumentHighlight;
( (function(MultiDocumentHighlight) {
    function from(multiDocumentHighlight) {
        return {
            uri: multiDocumentHighlight.uri,
            highlights: ( multiDocumentHighlight.highlights.map(DocumentHighlight.from))
        };
    }
    MultiDocumentHighlight.from = from;
    function to(multiDocumentHighlight) {
        return new MultiDocumentHighlight$1(URI.revive(multiDocumentHighlight.uri), ( multiDocumentHighlight.highlights.map(DocumentHighlight.to)));
    }
    MultiDocumentHighlight.to = to;
})(MultiDocumentHighlight || (MultiDocumentHighlight = {})));
var CompletionTriggerKind;
( (function(CompletionTriggerKind) {
    function to(kind) {
        switch (kind) {
            case 1 :
                return CompletionTriggerKind$1.TriggerCharacter;
            case 2 :
                return CompletionTriggerKind$1.TriggerForIncompleteCompletions;
            case 0 :
            default:
                return CompletionTriggerKind$1.Invoke;
        }
    }
    CompletionTriggerKind.to = to;
})(CompletionTriggerKind || (CompletionTriggerKind = {})));
var CompletionContext;
( (function(CompletionContext) {
    function to(context) {
        return {
            triggerKind: CompletionTriggerKind.to(context.triggerKind),
            triggerCharacter: context.triggerCharacter
        };
    }
    CompletionContext.to = to;
})(CompletionContext || (CompletionContext = {})));
var CompletionItemTag;
( (function(CompletionItemTag) {
    function from(kind) {
        switch (kind) {
            case CompletionItemTag$1.Deprecated: return 1 ;
        }
    }
    CompletionItemTag.from = from;
    function to(kind) {
        switch (kind) {
            case 1 : return CompletionItemTag$1.Deprecated;
        }
    }
    CompletionItemTag.to = to;
})(CompletionItemTag || (CompletionItemTag = {})));
var CompletionItemKind;
( (function(CompletionItemKind) {
    const _from = ( new Map([
        [CompletionItemKind$1.Method, 0 ],
        [CompletionItemKind$1.Function, 1 ],
        [CompletionItemKind$1.Constructor, 2 ],
        [CompletionItemKind$1.Field, 3 ],
        [CompletionItemKind$1.Variable, 4 ],
        [CompletionItemKind$1.Class, 5 ],
        [CompletionItemKind$1.Interface, 7 ],
        [CompletionItemKind$1.Struct, 6 ],
        [CompletionItemKind$1.Module, 8 ],
        [CompletionItemKind$1.Property, 9 ],
        [CompletionItemKind$1.Unit, 12 ],
        [CompletionItemKind$1.Value, 13 ],
        [CompletionItemKind$1.Constant, 14 ],
        [CompletionItemKind$1.Enum, 15 ],
        [CompletionItemKind$1.EnumMember, 16 ],
        [CompletionItemKind$1.Keyword, 17 ],
        [CompletionItemKind$1.Snippet, 27 ],
        [CompletionItemKind$1.Text, 18 ],
        [CompletionItemKind$1.Color, 19 ],
        [CompletionItemKind$1.File, 20 ],
        [CompletionItemKind$1.Reference, 21 ],
        [CompletionItemKind$1.Folder, 23 ],
        [CompletionItemKind$1.Event, 10 ],
        [CompletionItemKind$1.Operator, 11 ],
        [CompletionItemKind$1.TypeParameter, 24 ],
        [CompletionItemKind$1.Issue, 26 ],
        [CompletionItemKind$1.User, 25 ],
    ]));
    function from(kind) {
        return _from.get(kind) ?? 9 ;
    }
    CompletionItemKind.from = from;
    const _to = ( new Map([
        [0 , CompletionItemKind$1.Method],
        [1 , CompletionItemKind$1.Function],
        [2 , CompletionItemKind$1.Constructor],
        [3 , CompletionItemKind$1.Field],
        [4 , CompletionItemKind$1.Variable],
        [5 , CompletionItemKind$1.Class],
        [7 , CompletionItemKind$1.Interface],
        [6 , CompletionItemKind$1.Struct],
        [8 , CompletionItemKind$1.Module],
        [9 , CompletionItemKind$1.Property],
        [12 , CompletionItemKind$1.Unit],
        [13 , CompletionItemKind$1.Value],
        [14 , CompletionItemKind$1.Constant],
        [15 , CompletionItemKind$1.Enum],
        [16 , CompletionItemKind$1.EnumMember],
        [17 , CompletionItemKind$1.Keyword],
        [27 , CompletionItemKind$1.Snippet],
        [18 , CompletionItemKind$1.Text],
        [19 , CompletionItemKind$1.Color],
        [20 , CompletionItemKind$1.File],
        [21 , CompletionItemKind$1.Reference],
        [23 , CompletionItemKind$1.Folder],
        [10 , CompletionItemKind$1.Event],
        [11 , CompletionItemKind$1.Operator],
        [24 , CompletionItemKind$1.TypeParameter],
        [25 , CompletionItemKind$1.User],
        [26 , CompletionItemKind$1.Issue],
    ]));
    function to(kind) {
        return _to.get(kind) ?? CompletionItemKind$1.Property;
    }
    CompletionItemKind.to = to;
})(CompletionItemKind || (CompletionItemKind = {})));
var CompletionItem;
( (function(CompletionItem) {
    function to(suggestion, converter) {
        const result = new CompletionItem$1(suggestion.label);
        result.insertText = suggestion.insertText;
        result.kind = CompletionItemKind.to(suggestion.kind);
        result.tags = suggestion.tags?.map(CompletionItemTag.to);
        result.detail = suggestion.detail;
        result.documentation = isMarkdownString(suggestion.documentation) ? MarkdownString.to(suggestion.documentation) : suggestion.documentation;
        result.sortText = suggestion.sortText;
        result.filterText = suggestion.filterText;
        result.preselect = suggestion.preselect;
        result.commitCharacters = suggestion.commitCharacters;
        if (Range$2.isIRange(suggestion.range)) {
            result.range = Range.to(suggestion.range);
        }
        else if (typeof suggestion.range === 'object') {
            result.range = { inserting: Range.to(suggestion.range.insert), replacing: Range.to(suggestion.range.replace) };
        }
        result.keepWhitespace = typeof suggestion.insertTextRules === 'undefined' ? false : Boolean(suggestion.insertTextRules & 1 );
        if (typeof suggestion.insertTextRules !== 'undefined' && suggestion.insertTextRules & 4 ) {
            result.insertText = new SnippetString(suggestion.insertText);
        }
        else {
            result.insertText = suggestion.insertText;
            result.textEdit = result.range instanceof Range$1 ? new TextEdit$1(result.range, result.insertText) : undefined;
        }
        if (suggestion.additionalTextEdits && suggestion.additionalTextEdits.length > 0) {
            result.additionalTextEdits = ( suggestion.additionalTextEdits.map(e => TextEdit.to(e)));
        }
        result.command = converter && suggestion.command ? converter.fromInternal(suggestion.command) : undefined;
        return result;
    }
    CompletionItem.to = to;
})(CompletionItem || (CompletionItem = {})));
var ParameterInformation;
( (function(ParameterInformation) {
    function from(info) {
        if (typeof info.label !== 'string' && !Array.isArray(info.label)) {
            throw new TypeError('Invalid label');
        }
        return {
            label: info.label,
            documentation: MarkdownString.fromStrict(info.documentation)
        };
    }
    ParameterInformation.from = from;
    function to(info) {
        return {
            label: info.label,
            documentation: isMarkdownString(info.documentation) ? MarkdownString.to(info.documentation) : info.documentation
        };
    }
    ParameterInformation.to = to;
})(ParameterInformation || (ParameterInformation = {})));
var SignatureInformation;
( (function(SignatureInformation) {
    function from(info) {
        return {
            label: info.label,
            documentation: MarkdownString.fromStrict(info.documentation),
            parameters: Array.isArray(info.parameters) ? ( info.parameters.map(ParameterInformation.from)) : [],
            activeParameter: info.activeParameter,
        };
    }
    SignatureInformation.from = from;
    function to(info) {
        return {
            label: info.label,
            documentation: isMarkdownString(info.documentation) ? MarkdownString.to(info.documentation) : info.documentation,
            parameters: Array.isArray(info.parameters) ? ( info.parameters.map(ParameterInformation.to)) : [],
            activeParameter: info.activeParameter,
        };
    }
    SignatureInformation.to = to;
})(SignatureInformation || (SignatureInformation = {})));
var SignatureHelp;
( (function(SignatureHelp) {
    function from(help) {
        return {
            activeSignature: help.activeSignature,
            activeParameter: help.activeParameter,
            signatures: Array.isArray(help.signatures) ? ( help.signatures.map(SignatureInformation.from)) : [],
        };
    }
    SignatureHelp.from = from;
    function to(help) {
        return {
            activeSignature: help.activeSignature,
            activeParameter: help.activeParameter,
            signatures: Array.isArray(help.signatures) ? ( help.signatures.map(SignatureInformation.to)) : [],
        };
    }
    SignatureHelp.to = to;
})(SignatureHelp || (SignatureHelp = {})));
var InlayHint;
( (function(InlayHint) {
    function to(converter, hint) {
        const res = new InlayHint$1(Position.to(hint.position), typeof hint.label === 'string' ? hint.label : ( hint.label.map(InlayHintLabelPart.to.bind(undefined, converter))), hint.kind && InlayHintKind.to(hint.kind));
        res.textEdits = hint.textEdits && ( hint.textEdits.map(TextEdit.to));
        res.tooltip = isMarkdownString(hint.tooltip) ? MarkdownString.to(hint.tooltip) : hint.tooltip;
        res.paddingLeft = hint.paddingLeft;
        res.paddingRight = hint.paddingRight;
        return res;
    }
    InlayHint.to = to;
})(InlayHint || (InlayHint = {})));
var InlayHintLabelPart;
( (function(InlayHintLabelPart) {
    function to(converter, part) {
        const result = new InlayHintLabelPart$1(part.label);
        result.tooltip = isMarkdownString(part.tooltip)
            ? MarkdownString.to(part.tooltip)
            : part.tooltip;
        if (Command.is(part.command)) {
            result.command = converter.fromInternal(part.command);
        }
        if (part.location) {
            result.location = location.to(part.location);
        }
        return result;
    }
    InlayHintLabelPart.to = to;
})(InlayHintLabelPart || (InlayHintLabelPart = {})));
var InlayHintKind;
( (function(InlayHintKind) {
    function from(kind) {
        return kind;
    }
    InlayHintKind.from = from;
    function to(kind) {
        return kind;
    }
    InlayHintKind.to = to;
})(InlayHintKind || (InlayHintKind = {})));
var DocumentLink;
( (function(DocumentLink) {
    function from(link) {
        return {
            range: Range.from(link.range),
            url: link.target,
            tooltip: link.tooltip
        };
    }
    DocumentLink.from = from;
    function to(link) {
        let target = undefined;
        if (link.url) {
            try {
                target = typeof link.url === 'string' ? ( URI.parse(link.url, true)) : URI.revive(link.url);
            }
            catch (err) {
            }
        }
        return new DocumentLink$1(Range.to(link.range), target);
    }
    DocumentLink.to = to;
})(DocumentLink || (DocumentLink = {})));
var ColorPresentation;
( (function(ColorPresentation) {
    function to(colorPresentation) {
        const cp = new ColorPresentation$1(colorPresentation.label);
        if (colorPresentation.textEdit) {
            cp.textEdit = TextEdit.to(colorPresentation.textEdit);
        }
        if (colorPresentation.additionalTextEdits) {
            cp.additionalTextEdits = ( colorPresentation.additionalTextEdits.map(value => TextEdit.to(value)));
        }
        return cp;
    }
    ColorPresentation.to = to;
    function from(colorPresentation) {
        return {
            label: colorPresentation.label,
            textEdit: colorPresentation.textEdit ? TextEdit.from(colorPresentation.textEdit) : undefined,
            additionalTextEdits: colorPresentation.additionalTextEdits ? ( colorPresentation.additionalTextEdits.map(value => TextEdit.from(value))) : undefined
        };
    }
    ColorPresentation.from = from;
})(ColorPresentation || (ColorPresentation = {})));
var Color;
( (function(Color) {
    function to(c) {
        return new Color$1(c[0], c[1], c[2], c[3]);
    }
    Color.to = to;
    function from(color) {
        return [color.red, color.green, color.blue, color.alpha];
    }
    Color.from = from;
})(Color || (Color = {})));
var SelectionRange;
( (function(SelectionRange) {
    function from(obj) {
        return { range: Range.from(obj.range) };
    }
    SelectionRange.from = from;
    function to(obj) {
        return new SelectionRange$1(Range.to(obj.range));
    }
    SelectionRange.to = to;
})(SelectionRange || (SelectionRange = {})));
var TextDocumentSaveReason;
( (function(TextDocumentSaveReason) {
    function to(reason) {
        switch (reason) {
            case 2 :
                return TextDocumentSaveReason$1.AfterDelay;
            case 1 :
                return TextDocumentSaveReason$1.Manual;
            case 3 :
            case 4 :
                return TextDocumentSaveReason$1.FocusOut;
        }
    }
    TextDocumentSaveReason.to = to;
})(TextDocumentSaveReason || (TextDocumentSaveReason = {})));
var TextEditorLineNumbersStyle;
( (function(TextEditorLineNumbersStyle) {
    function from(style) {
        switch (style) {
            case TextEditorLineNumbersStyle$1.Off:
                return 0 ;
            case TextEditorLineNumbersStyle$1.Relative:
                return 2 ;
            case TextEditorLineNumbersStyle$1.Interval:
                return 3 ;
            case TextEditorLineNumbersStyle$1.On:
            default:
                return 1 ;
        }
    }
    TextEditorLineNumbersStyle.from = from;
    function to(style) {
        switch (style) {
            case 0 :
                return TextEditorLineNumbersStyle$1.Off;
            case 2 :
                return TextEditorLineNumbersStyle$1.Relative;
            case 3 :
                return TextEditorLineNumbersStyle$1.Interval;
            case 1 :
            default:
                return TextEditorLineNumbersStyle$1.On;
        }
    }
    TextEditorLineNumbersStyle.to = to;
})(TextEditorLineNumbersStyle || (TextEditorLineNumbersStyle = {})));
var EndOfLine;
( (function(EndOfLine) {
    function from(eol) {
        if (eol === EndOfLine$1.CRLF) {
            return 1 ;
        }
        else if (eol === EndOfLine$1.LF) {
            return 0 ;
        }
        return undefined;
    }
    EndOfLine.from = from;
    function to(eol) {
        if (eol === 1 ) {
            return EndOfLine$1.CRLF;
        }
        else if (eol === 0 ) {
            return EndOfLine$1.LF;
        }
        return undefined;
    }
    EndOfLine.to = to;
})(EndOfLine || (EndOfLine = {})));
var ProgressLocation;
( (function(ProgressLocation) {
    function from(loc) {
        if (typeof loc === 'object') {
            return loc.viewId;
        }
        switch (loc) {
            case ProgressLocation$1.SourceControl: return 3 ;
            case ProgressLocation$1.Window: return 10 ;
            case ProgressLocation$1.Notification: return 15 ;
        }
        throw new Error(`Unknown 'ProgressLocation'`);
    }
    ProgressLocation.from = from;
})(ProgressLocation || (ProgressLocation = {})));
var FoldingRange;
( (function(FoldingRange) {
    function from(r) {
        const range = { start: r.start + 1, end: r.end + 1 };
        if (r.kind) {
            range.kind = FoldingRangeKind.from(r.kind);
        }
        return range;
    }
    FoldingRange.from = from;
    function to(r) {
        const range = { start: r.start - 1, end: r.end - 1 };
        if (r.kind) {
            range.kind = FoldingRangeKind.to(r.kind);
        }
        return range;
    }
    FoldingRange.to = to;
})(FoldingRange || (FoldingRange = {})));
var FoldingRangeKind;
( (function(FoldingRangeKind) {
    function from(kind) {
        if (kind) {
            switch (kind) {
                case FoldingRangeKind$1.Comment:
                    return FoldingRangeKind$2.Comment;
                case FoldingRangeKind$1.Imports:
                    return FoldingRangeKind$2.Imports;
                case FoldingRangeKind$1.Region:
                    return FoldingRangeKind$2.Region;
            }
        }
        return undefined;
    }
    FoldingRangeKind.from = from;
    function to(kind) {
        if (kind) {
            switch (kind.value) {
                case FoldingRangeKind$2.Comment.value:
                    return FoldingRangeKind$1.Comment;
                case FoldingRangeKind$2.Imports.value:
                    return FoldingRangeKind$1.Imports;
                case FoldingRangeKind$2.Region.value:
                    return FoldingRangeKind$1.Region;
            }
        }
        return undefined;
    }
    FoldingRangeKind.to = to;
})(FoldingRangeKind || (FoldingRangeKind = {})));
var TextEditorOpenOptions;
( (function(TextEditorOpenOptions) {
    function from(options) {
        if (options) {
            return {
                pinned: typeof options.preview === 'boolean' ? !options.preview : undefined,
                inactive: options.background,
                preserveFocus: options.preserveFocus,
                selection: typeof options.selection === 'object' ? Range.from(options.selection) : undefined,
                override: typeof options.override === 'boolean' ? DEFAULT_EDITOR_ASSOCIATION.id : undefined
            };
        }
        return undefined;
    }
    TextEditorOpenOptions.from = from;
})(TextEditorOpenOptions || (TextEditorOpenOptions = {})));
var GlobPattern;
( (function(GlobPattern) {
    function from(pattern) {
        if (pattern instanceof RelativePattern) {
            return pattern.toJSON();
        }
        if (typeof pattern === 'string') {
            return pattern;
        }
        if (isRelativePatternShape(pattern) || isLegacyRelativePatternShape(pattern)) {
            return new RelativePattern(pattern.baseUri ?? pattern.base, pattern.pattern).toJSON();
        }
        return pattern;
    }
    GlobPattern.from = from;
    function isRelativePatternShape(obj) {
        const rp = obj;
        if (!rp) {
            return false;
        }
        return URI.isUri(rp.baseUri) && typeof rp.pattern === 'string';
    }
    function isLegacyRelativePatternShape(obj) {
        const rp = obj;
        if (!rp) {
            return false;
        }
        return typeof rp.base === 'string' && typeof rp.pattern === 'string';
    }
    function to(pattern) {
        if (typeof pattern === 'string') {
            return pattern;
        }
        return new RelativePattern(URI.revive(pattern.baseUri), pattern.pattern);
    }
    GlobPattern.to = to;
})(GlobPattern || (GlobPattern = {})));
var LanguageSelector;
( (function(LanguageSelector) {
    function from(selector) {
        if (!selector) {
            return undefined;
        }
        else if (Array.isArray(selector)) {
            return ( selector.map(from));
        }
        else if (typeof selector === 'string') {
            return selector;
        }
        else {
            const filter = selector;
            return {
                language: filter.language,
                scheme: filter.scheme,
                pattern: GlobPattern.from(filter.pattern),
                exclusive: filter.exclusive,
                notebookType: filter.notebookType
            };
        }
    }
    LanguageSelector.from = from;
})(LanguageSelector || (LanguageSelector = {})));
var MappedEditsContext;
( (function(MappedEditsContext) {
    function is(v) {
        return (!!v && typeof v === 'object' &&
            'documents' in v &&
            Array.isArray(v.documents) &&
            v.documents.every(subArr => Array.isArray(subArr) &&
                subArr.every(docRef => docRef && typeof docRef === 'object' &&
                    'uri' in docRef && URI.isUri(docRef.uri) &&
                    'version' in docRef && typeof docRef.version === 'number' &&
                    'ranges' in docRef && Array.isArray(docRef.ranges) && docRef.ranges.every((r) => r instanceof Range$1))));
    }
    MappedEditsContext.is = is;
    function from(extContext) {
        return {
            documents: ( extContext.documents.map((subArray) => ( subArray.map((r) => ({
                uri: ( URI.from(r.uri)),
                version: r.version,
                ranges: ( r.ranges.map((r) => Range.from(r))),
            }))))),
        };
    }
    MappedEditsContext.from = from;
})(MappedEditsContext || (MappedEditsContext = {})));
var NotebookRange;
( (function(NotebookRange) {
    function from(range) {
        return { start: range.start, end: range.end };
    }
    NotebookRange.from = from;
    function to(range) {
        return new NotebookRange$1(range.start, range.end);
    }
    NotebookRange.to = to;
})(NotebookRange || (NotebookRange = {})));
var NotebookCellExecutionSummary;
( (function(NotebookCellExecutionSummary) {
    function to(data) {
        return {
            timing: typeof data.runStartTime === 'number' && typeof data.runEndTime === 'number' ? { startTime: data.runStartTime, endTime: data.runEndTime } : undefined,
            executionOrder: data.executionOrder,
            success: data.lastRunSuccess
        };
    }
    NotebookCellExecutionSummary.to = to;
    function from(data) {
        return {
            lastRunSuccess: data.success,
            runStartTime: data.timing?.startTime,
            runEndTime: data.timing?.endTime,
            executionOrder: data.executionOrder
        };
    }
    NotebookCellExecutionSummary.from = from;
})(NotebookCellExecutionSummary || (NotebookCellExecutionSummary = {})));
var NotebookCellExecutionState;
( (function(NotebookCellExecutionState) {
    function to(state) {
        if (state === NotebookCellExecutionState$1.Unconfirmed) {
            return NotebookCellExecutionState$2.Pending;
        }
        else if (state === NotebookCellExecutionState$1.Pending) {
            return undefined;
        }
        else if (state === NotebookCellExecutionState$1.Executing) {
            return NotebookCellExecutionState$2.Executing;
        }
        else {
            throw new Error(`Unknown state: ${state}`);
        }
    }
    NotebookCellExecutionState.to = to;
})(NotebookCellExecutionState || (NotebookCellExecutionState = {})));
var NotebookCellKind;
( (function(NotebookCellKind) {
    function from(data) {
        switch (data) {
            case NotebookCellKind$1.Markup:
                return CellKind.Markup;
            case NotebookCellKind$1.Code:
            default:
                return CellKind.Code;
        }
    }
    NotebookCellKind.from = from;
    function to(data) {
        switch (data) {
            case CellKind.Markup:
                return NotebookCellKind$1.Markup;
            case CellKind.Code:
            default:
                return NotebookCellKind$1.Code;
        }
    }
    NotebookCellKind.to = to;
})(NotebookCellKind || (NotebookCellKind = {})));
var NotebookData;
( (function(NotebookData) {
    function from(data) {
        const res = {
            metadata: data.metadata ?? Object.create(null),
            cells: [],
        };
        for (const cell of data.cells) {
            NotebookCellData$1.validate(cell);
            res.cells.push(NotebookCellData.from(cell));
        }
        return res;
    }
    NotebookData.from = from;
    function to(data) {
        const res = new NotebookData$1(( data.cells.map(NotebookCellData.to)));
        if (!isEmptyObject(data.metadata)) {
            res.metadata = data.metadata;
        }
        return res;
    }
    NotebookData.to = to;
})(NotebookData || (NotebookData = {})));
var NotebookCellData;
( (function(NotebookCellData) {
    function from(data) {
        return {
            cellKind: NotebookCellKind.from(data.kind),
            language: data.languageId,
            mime: data.mime,
            source: data.value,
            metadata: data.metadata,
            internalMetadata: NotebookCellExecutionSummary.from(data.executionSummary ?? {}),
            outputs: data.outputs ? ( data.outputs.map(NotebookCellOutput.from)) : []
        };
    }
    NotebookCellData.from = from;
    function to(data) {
        return new NotebookCellData$1(NotebookCellKind.to(data.cellKind), data.source, data.language, data.mime, data.outputs ? ( data.outputs.map(NotebookCellOutput.to)) : undefined, data.metadata, data.internalMetadata ? NotebookCellExecutionSummary.to(data.internalMetadata) : undefined);
    }
    NotebookCellData.to = to;
})(NotebookCellData || (NotebookCellData = {})));
var NotebookCellOutputItem;
( (function(NotebookCellOutputItem) {
    function from(item) {
        return {
            mime: item.mime,
            valueBytes: VSBuffer.wrap(item.data),
        };
    }
    NotebookCellOutputItem.from = from;
    function to(item) {
        return new NotebookCellOutputItem$1(item.valueBytes.buffer, item.mime);
    }
    NotebookCellOutputItem.to = to;
})(NotebookCellOutputItem || (NotebookCellOutputItem = {})));
var NotebookCellOutput;
( (function(NotebookCellOutput) {
    function from(output) {
        return {
            outputId: output.id,
            items: ( output.items.map(NotebookCellOutputItem.from)),
            metadata: output.metadata
        };
    }
    NotebookCellOutput.from = from;
    function to(output) {
        const items = ( output.items.map(NotebookCellOutputItem.to));
        return new NotebookCellOutput$1(items, output.outputId, output.metadata);
    }
    NotebookCellOutput.to = to;
})(NotebookCellOutput || (NotebookCellOutput = {})));
var NotebookExclusiveDocumentPattern;
( (function(NotebookExclusiveDocumentPattern) {
    function from(pattern) {
        if (isExclusivePattern(pattern)) {
            return {
                include: GlobPattern.from(pattern.include) ?? undefined,
                exclude: GlobPattern.from(pattern.exclude) ?? undefined,
            };
        }
        return GlobPattern.from(pattern) ?? undefined;
    }
    NotebookExclusiveDocumentPattern.from = from;
    function to(pattern) {
        if (isExclusivePattern(pattern)) {
            return {
                include: GlobPattern.to(pattern.include),
                exclude: GlobPattern.to(pattern.exclude)
            };
        }
        return GlobPattern.to(pattern);
    }
    NotebookExclusiveDocumentPattern.to = to;
    function isExclusivePattern(obj) {
        const ep = obj;
        if (!ep) {
            return false;
        }
        return !isUndefinedOrNull(ep.include) && !isUndefinedOrNull(ep.exclude);
    }
})(
    NotebookExclusiveDocumentPattern || (NotebookExclusiveDocumentPattern = {})
));
var NotebookStatusBarItem;
( (function(NotebookStatusBarItem) {
    function from(item, commandsConverter, disposables) {
        const command = typeof item.command === 'string' ? { title: '', command: item.command } : item.command;
        return {
            alignment: item.alignment === NotebookCellStatusBarAlignment.Left ? 1  : 2 ,
            command: commandsConverter.toInternal(command, disposables),
            text: item.text,
            tooltip: item.tooltip,
            accessibilityInformation: item.accessibilityInformation,
            priority: item.priority
        };
    }
    NotebookStatusBarItem.from = from;
})(NotebookStatusBarItem || (NotebookStatusBarItem = {})));
var NotebookKernelSourceAction;
( (function(NotebookKernelSourceAction) {
    function from(item, commandsConverter, disposables) {
        const command = typeof item.command === 'string' ? { title: '', command: item.command } : item.command;
        return {
            command: commandsConverter.toInternal(command, disposables),
            label: item.label,
            description: item.description,
            detail: item.detail,
            documentation: item.documentation
        };
    }
    NotebookKernelSourceAction.from = from;
})(NotebookKernelSourceAction || (NotebookKernelSourceAction = {})));
var NotebookDocumentContentOptions;
( (function(NotebookDocumentContentOptions) {
    function from(options) {
        return {
            transientOutputs: options?.transientOutputs ?? false,
            transientCellMetadata: options?.transientCellMetadata ?? {},
            transientDocumentMetadata: options?.transientDocumentMetadata ?? {},
            cellContentMetadata: options?.cellContentMetadata ?? {}
        };
    }
    NotebookDocumentContentOptions.from = from;
})(NotebookDocumentContentOptions || (NotebookDocumentContentOptions = {})));
var NotebookRendererScript;
( (function(NotebookRendererScript) {
    function from(preload) {
        return {
            uri: preload.uri,
            provides: preload.provides
        };
    }
    NotebookRendererScript.from = from;
    function to(preload) {
        return new NotebookRendererScript$1(URI.revive(preload.uri), preload.provides);
    }
    NotebookRendererScript.to = to;
})(NotebookRendererScript || (NotebookRendererScript = {})));
var TestMessage;
( (function(TestMessage) {
    function from(message) {
        return {
            message: MarkdownString.fromStrict(message.message) || '',
            type: 0 ,
            expected: message.expectedOutput,
            actual: message.actualOutput,
            contextValue: message.contextValue,
            location: message.location && ({ range: Range.from(message.location.range), uri: message.location.uri }),
        };
    }
    TestMessage.from = from;
    function to(item) {
        const message = new TestMessage$1(typeof item.message === 'string' ? item.message : MarkdownString.to(item.message));
        message.actualOutput = item.actual;
        message.expectedOutput = item.expected;
        message.contextValue = item.contextValue;
        message.location = item.location ? location.to(item.location) : undefined;
        return message;
    }
    TestMessage.to = to;
})(TestMessage || (TestMessage = {})));
var TestTag;
( (function(TestTag) {
    TestTag.namespace = namespaceTestTag;
    TestTag.denamespace = denamespaceTestTag;
})(TestTag || (TestTag = {})));
var TestItem;
( (function(TestItem) {
    function from(item) {
        const ctrlId = getPrivateApiFor(item).controllerId;
        return {
            extId: ( TestId.fromExtHostTestItem(item, ctrlId).toString()),
            label: item.label,
            uri: URI.revive(item.uri),
            busy: item.busy,
            tags: ( item.tags.map(t => TestTag.namespace(ctrlId, t.id))),
            range: Range$2.lift(Range.from(item.range)),
            description: item.description || null,
            sortText: item.sortText || null,
            error: item.error ? (MarkdownString.fromStrict(item.error) || null) : null,
        };
    }
    TestItem.from = from;
    function toPlain(item) {
        return {
            parent: undefined,
            error: undefined,
            id: TestId.fromString(item.extId).localId,
            label: item.label,
            uri: URI.revive(item.uri),
            tags: ( (item.tags || []).map(t => {
                const { tagId } = TestTag.denamespace(t);
                return new TestTag$1(tagId);
            })),
            children: {
                add: () => { },
                delete: () => { },
                forEach: () => { },
                *[Symbol.iterator]() { },
                get: () => undefined,
                replace: () => { },
                size: 0,
            },
            range: Range.to(item.range || undefined),
            canResolveChildren: false,
            busy: item.busy,
            description: item.description || undefined,
            sortText: item.sortText || undefined,
        };
    }
    TestItem.toPlain = toPlain;
})(TestItem || (TestItem = {})));
( (function(TestTag) {
    function from(tag) {
        return { id: tag.id };
    }
    TestTag.from = from;
    function to(tag) {
        return new TestTag$1(tag.id);
    }
    TestTag.to = to;
})(TestTag || (TestTag = {})));
var TestResults;
( (function(TestResults) {
    const convertTestResultItem = (item, byInternalId) => {
        const children = [];
        for (const [id, item] of byInternalId) {
            if (TestId.compare(item.item.extId, id) === 2 ) {
                byInternalId.delete(id);
                children.push(item);
            }
        }
        const snapshot = ({
            ...TestItem.toPlain(item.item),
            parent: undefined,
            taskStates: ( item.tasks.map(t => ({
                state: t.state,
                duration: t.duration,
                messages: ( t.messages
                    .filter((m) => m.type === 0 )
                    .map(TestMessage.to)),
            }))),
            children: ( children.map(c => convertTestResultItem(c, byInternalId)))
        });
        for (const child of snapshot.children) {
            child.parent = snapshot;
        }
        return snapshot;
    };
    function to(serialized) {
        const roots = [];
        const byInternalId = ( new Map());
        for (const item of serialized.items) {
            byInternalId.set(item.item.extId, item);
            const controllerId = TestId.root(item.item.extId);
            if (( serialized.request.targets.some(
                t => t.controllerId === controllerId && t.testIds.includes(item.item.extId)
            ))) {
                roots.push(item);
            }
        }
        return {
            completedAt: serialized.completedAt,
            results: ( roots.map(r => convertTestResultItem(r, byInternalId))),
        };
    }
    TestResults.to = to;
})(TestResults || (TestResults = {})));
var TestCoverage;
( (function(TestCoverage) {
    function fromCoveredCount(count) {
        return { covered: count.covered, total: count.total };
    }
    function fromLocation(location) {
        return 'line' in location ? Position.from(location) : Range.from(location);
    }
    function fromDetailed(coverage) {
        if ('branches' in coverage) {
            return {
                count: coverage.executed,
                location: fromLocation(coverage.location),
                type: 1 ,
                branches: coverage.branches.length
                    ? ( coverage.branches.map(
                    b => ({ count: b.executed, location: b.location && fromLocation(b.location), label: b.label })
                ))
                    : undefined,
            };
        }
        else {
            return {
                type: 0 ,
                name: coverage.name,
                count: coverage.executed,
                location: fromLocation(coverage.location),
            };
        }
    }
    TestCoverage.fromDetailed = fromDetailed;
    function fromFile(coverage) {
        return {
            uri: coverage.uri,
            statement: fromCoveredCount(coverage.statementCoverage),
            branch: coverage.branchCoverage && fromCoveredCount(coverage.branchCoverage),
            declaration: coverage.declarationCoverage && fromCoveredCount(coverage.declarationCoverage),
            details: coverage.detailedCoverage?.map(fromDetailed),
        };
    }
    TestCoverage.fromFile = fromFile;
})(TestCoverage || (TestCoverage = {})));
var CodeActionTriggerKind;
( (function(CodeActionTriggerKind) {
    function to(value) {
        switch (value) {
            case 1 :
                return CodeActionTriggerKind$1.Invoke;
            case 2 :
                return CodeActionTriggerKind$1.Automatic;
        }
    }
    CodeActionTriggerKind.to = to;
})(CodeActionTriggerKind || (CodeActionTriggerKind = {})));
var TypeHierarchyItem;
( (function(TypeHierarchyItem) {
    function to(item) {
        const result = new TypeHierarchyItem$1(SymbolKind.to(item.kind), item.name, item.detail || '', URI.revive(item.uri), Range.to(item.range), Range.to(item.selectionRange));
        result._sessionId = item._sessionId;
        result._itemId = item._itemId;
        return result;
    }
    TypeHierarchyItem.to = to;
    function from(item, sessionId, itemId) {
        sessionId = sessionId ?? item._sessionId;
        itemId = itemId ?? item._itemId;
        if (sessionId === undefined || itemId === undefined) {
            throw new Error('invalid item');
        }
        return {
            _sessionId: sessionId,
            _itemId: itemId,
            kind: SymbolKind.from(item.kind),
            name: item.name,
            detail: item.detail ?? '',
            uri: item.uri,
            range: Range.from(item.range),
            selectionRange: Range.from(item.selectionRange),
            tags: item.tags?.map(SymbolTag.from)
        };
    }
    TypeHierarchyItem.from = from;
})(TypeHierarchyItem || (TypeHierarchyItem = {})));
var ViewBadge;
( (function(ViewBadge) {
    function from(badge) {
        if (!badge) {
            return undefined;
        }
        return {
            value: badge.value,
            tooltip: badge.tooltip
        };
    }
    ViewBadge.from = from;
})(ViewBadge || (ViewBadge = {})));
var DataTransferItem;
( (function(DataTransferItem) {
    function to(mime, item, resolveFileData) {
        const file = item.fileData;
        if (file) {
            return new InternalFileDataTransferItem(new DataTransferFile(file.name, URI.revive(file.uri), file.id, createSingleCallFunction(() => resolveFileData(file.id))));
        }
        if (mime === Mimes.uriList && item.uriListData) {
            return new InternalDataTransferItem(reviveUriList(item.uriListData));
        }
        return new InternalDataTransferItem(item.asString);
    }
    DataTransferItem.to = to;
    async function from(mime, item) {
        const stringValue = await item.asString();
        if (mime === Mimes.uriList) {
            return {
                asString: stringValue,
                fileData: undefined,
                uriListData: serializeUriList(stringValue),
            };
        }
        const fileValue = item.asFile();
        return {
            asString: stringValue,
            fileData: fileValue ? {
                name: fileValue.name,
                uri: fileValue.uri,
                id: fileValue._itemId ?? fileValue.id,
            } : undefined,
        };
    }
    DataTransferItem.from = from;
    function serializeUriList(stringValue) {
        return ( UriList.split(stringValue).map(part => {
            if (part.startsWith('#')) {
                return part;
            }
            try {
                return ( URI.parse(part));
            }
            catch {
            }
            return part;
        }));
    }
    function reviveUriList(parts) {
        return UriList.create(( parts.map(part => {
            return typeof part === 'string' ? part : URI.revive(part);
        })));
    }
})(DataTransferItem || (DataTransferItem = {})));
var DataTransfer;
( (function(DataTransfer) {
    function toDataTransfer(value, resolveFileData) {
        const init = ( value.items.map(([type, item]) => {
            return [type, DataTransferItem.to(type, item, resolveFileData)];
        }));
        return new DataTransfer$1(init);
    }
    DataTransfer.toDataTransfer = toDataTransfer;
    async function from(dataTransfer) {
        const newDTO = { items: [] };
        const promises = [];
        for (const [mime, value] of dataTransfer) {
            promises.push((async () => {
                newDTO.items.push([mime, await DataTransferItem.from(mime, value)]);
            })());
        }
        await Promise.all(promises);
        return newDTO;
    }
    DataTransfer.from = from;
})(DataTransfer || (DataTransfer = {})));
var ChatFollowup;
( (function(ChatFollowup) {
    function from(followup, request) {
        return {
            kind: 'reply',
            agentId: followup.participant ?? request?.agentId ?? '',
            subCommand: followup.command ?? request?.command,
            message: followup.prompt,
            title: followup.label
        };
    }
    ChatFollowup.from = from;
    function to(followup) {
        return {
            prompt: followup.message,
            label: followup.title,
            participant: followup.agentId,
            command: followup.subCommand,
        };
    }
    ChatFollowup.to = to;
})(ChatFollowup || (ChatFollowup = {})));
var ChatInlineFollowup;
( (function(ChatInlineFollowup) {
    function from(followup) {
        if ('commandId' in followup) {
            return {
                kind: 'command',
                title: followup.title ?? '',
                commandId: followup.commandId ?? '',
                when: followup.when ?? '',
                args: followup.args
            };
        }
        else {
            return {
                kind: 'reply',
                message: followup.message,
                title: followup.title,
                tooltip: followup.tooltip,
            };
        }
    }
    ChatInlineFollowup.from = from;
})(ChatInlineFollowup || (ChatInlineFollowup = {})));
var LanguageModelMessage;
( (function(LanguageModelMessage) {
    function to(message) {
        switch (message.role) {
            case 0 : return new LanguageModelSystemMessage(message.content);
            case 1 : return new LanguageModelUserMessage(message.content);
            case 2 : return new LanguageModelAssistantMessage(message.content);
        }
    }
    LanguageModelMessage.to = to;
    function from(message) {
        if (message instanceof LanguageModelSystemMessage) {
            return { role: 0 , content: message.content };
        }
        else if (message instanceof LanguageModelUserMessage) {
            return { role: 1 , content: message.content };
        }
        else if (message instanceof LanguageModelAssistantMessage) {
            return { role: 2 , content: message.content };
        }
        else {
            throw new Error('Invalid LanguageModelMessage');
        }
    }
    LanguageModelMessage.from = from;
})(LanguageModelMessage || (LanguageModelMessage = {})));
var ChatVariable;
( (function(ChatVariable) {
    function objectTo(variableObject) {
        const result = {};
        for (const key of ( Object.keys(variableObject))) {
            result[key] = ( variableObject[key].map(ChatVariable.to));
        }
        return result;
    }
    ChatVariable.objectTo = objectTo;
    function to(variable) {
        return {
            level: ChatVariableLevel.to(variable.level),
            kind: variable.kind,
            value: isUriComponents(variable.value) ? URI.revive(variable.value) : variable.value,
            description: variable.description
        };
    }
    ChatVariable.to = to;
    function from(variable) {
        return {
            level: ChatVariableLevel.from(variable.level),
            kind: variable.kind,
            value: variable.value,
            description: variable.description
        };
    }
    ChatVariable.from = from;
})(ChatVariable || (ChatVariable = {})));
var ChatVariableLevel;
( (function(ChatVariableLevel) {
    function to(level) {
        switch (level) {
            case 'short': return ChatVariableLevel$1.Short;
            case 'medium': return ChatVariableLevel$1.Medium;
            case 'full':
            default:
                return ChatVariableLevel$1.Full;
        }
    }
    ChatVariableLevel.to = to;
    function from(level) {
        switch (level) {
            case ChatVariableLevel$1.Short: return 'short';
            case ChatVariableLevel$1.Medium: return 'medium';
            case ChatVariableLevel$1.Full:
            default:
                return 'full';
        }
    }
    ChatVariableLevel.from = from;
})(ChatVariableLevel || (ChatVariableLevel = {})));
var InteractiveEditorResponseFeedbackKind;
( (function(InteractiveEditorResponseFeedbackKind) {
    function to(kind) {
        switch (kind) {
            case 1 :
                return InteractiveEditorResponseFeedbackKind$1.Helpful;
            case 0 :
                return InteractiveEditorResponseFeedbackKind$1.Unhelpful;
            case 2 :
                return InteractiveEditorResponseFeedbackKind$1.Undone;
            case 3 :
                return InteractiveEditorResponseFeedbackKind$1.Accepted;
            case 4 :
                return InteractiveEditorResponseFeedbackKind$1.Bug;
        }
    }
    InteractiveEditorResponseFeedbackKind.to = to;
})(
    InteractiveEditorResponseFeedbackKind || (InteractiveEditorResponseFeedbackKind = {})
));
var ChatResponseMarkdownPart;
( (function(ChatResponseMarkdownPart) {
    function to(part) {
        return {
            kind: 'markdownContent',
            content: MarkdownString.from(part.value)
        };
    }
    ChatResponseMarkdownPart.to = to;
    function from(part) {
        return new ChatResponseMarkdownPart$1(MarkdownString.to(part.content));
    }
    ChatResponseMarkdownPart.from = from;
})(ChatResponseMarkdownPart || (ChatResponseMarkdownPart = {})));
var ChatResponseFilesPart;
( (function(ChatResponseFilesPart) {
    function to(part) {
        const { value, baseUri } = part;
        function convert(items, baseUri) {
            return ( items.map(item => {
                const myUri = URI.joinPath(baseUri, item.name);
                return {
                    label: item.name,
                    uri: myUri,
                    children: item.children && convert(item.children, myUri)
                };
            }));
        }
        return {
            kind: 'treeData',
            treeData: {
                label: basename(baseUri),
                uri: baseUri,
                children: convert(value, baseUri)
            }
        };
    }
    ChatResponseFilesPart.to = to;
    function from(part) {
        const treeData = revive(part.treeData);
        function convert(items) {
            return ( items.map(item => {
                return {
                    name: item.label,
                    children: item.children && convert(item.children)
                };
            }));
        }
        const baseUri = treeData.uri;
        const items = treeData.children ? convert(treeData.children) : [];
        return new ChatResponseFileTreePart(items, baseUri);
    }
    ChatResponseFilesPart.from = from;
})(ChatResponseFilesPart || (ChatResponseFilesPart = {})));
var ChatResponseAnchorPart;
( (function(ChatResponseAnchorPart) {
    function to(part) {
        return {
            kind: 'inlineReference',
            name: part.title,
            inlineReference: !URI.isUri(part.value) ? Location.from(part.value) : part.value
        };
    }
    ChatResponseAnchorPart.to = to;
    function from(part) {
        const value = revive(part);
        return new ChatResponseAnchorPart$1(URI.isUri(value.inlineReference) ? value.inlineReference : Location.to(value.inlineReference), part.name);
    }
    ChatResponseAnchorPart.from = from;
})(ChatResponseAnchorPart || (ChatResponseAnchorPart = {})));
var ChatResponseProgressPart;
( (function(ChatResponseProgressPart) {
    function to(part) {
        return {
            kind: 'progressMessage',
            content: MarkdownString.from(part.value)
        };
    }
    ChatResponseProgressPart.to = to;
    function from(part) {
        return new ChatResponseProgressPart$1(part.content.value);
    }
    ChatResponseProgressPart.from = from;
})(ChatResponseProgressPart || (ChatResponseProgressPart = {})));
var ChatResponseCommandButtonPart;
( (function(ChatResponseCommandButtonPart) {
    function to(part, commandsConverter, commandDisposables) {
        const command = commandsConverter.toInternal(part.value, commandDisposables) ?? { command: part.value.command, title: part.value.title };
        return {
            kind: 'command',
            command
        };
    }
    ChatResponseCommandButtonPart.to = to;
    function from(part, commandsConverter) {
        return new ChatResponseCommandButtonPart$1(commandsConverter.fromInternal(part.command) ?? { command: part.command.id, title: part.command.title });
    }
    ChatResponseCommandButtonPart.from = from;
})(ChatResponseCommandButtonPart || (ChatResponseCommandButtonPart = {})));
var ChatResponseReferencePart;
( (function(ChatResponseReferencePart) {
    function to(part) {
        return {
            kind: 'reference',
            reference: !URI.isUri(part.value) ? Location.from(part.value) : part.value
        };
    }
    ChatResponseReferencePart.to = to;
    function from(part) {
        const value = revive(part);
        return new ChatResponseReferencePart$1(URI.isUri(value.reference) ? value.reference : Location.to(value.reference));
    }
    ChatResponseReferencePart.from = from;
})(ChatResponseReferencePart || (ChatResponseReferencePart = {})));
var ChatResponsePart;
( (function(ChatResponsePart) {
    function to(part) {
        if (part instanceof ChatResponseMarkdownPart$1) {
            return ChatResponseMarkdownPart.to(part);
        }
        else if (part instanceof ChatResponseAnchorPart$1) {
            return ChatResponseAnchorPart.to(part);
        }
        else if (part instanceof ChatResponseReferencePart$1) {
            return ChatResponseReferencePart.to(part);
        }
        else if (part instanceof ChatResponseProgressPart$1) {
            return ChatResponseProgressPart.to(part);
        }
        else if (part instanceof ChatResponseFileTreePart) {
            return ChatResponseFilesPart.to(part);
        }
        return {
            kind: 'content',
            content: ''
        };
    }
    ChatResponsePart.to = to;
    function from(part, commandsConverter) {
        switch (part.kind) {
            case 'reference': return ChatResponseReferencePart.from(part);
            case 'markdownContent':
            case 'inlineReference':
            case 'progressMessage':
            case 'treeData':
            case 'command':
                return fromContent(part, commandsConverter);
        }
        return undefined;
    }
    ChatResponsePart.from = from;
    function fromContent(part, commandsConverter) {
        switch (part.kind) {
            case 'markdownContent': return ChatResponseMarkdownPart.from(part);
            case 'inlineReference': return ChatResponseAnchorPart.from(part);
            case 'progressMessage': return undefined;
            case 'treeData': return ChatResponseFilesPart.from(part);
            case 'command': return ChatResponseCommandButtonPart.from(part, commandsConverter);
        }
        return undefined;
    }
    ChatResponsePart.fromContent = fromContent;
})(ChatResponsePart || (ChatResponsePart = {})));
var ChatResponseProgress;
( (function(ChatResponseProgress) {
    function from(extension, progress) {
        if ('markdownContent' in progress) {
            checkProposedApiEnabled(extension, 'chatParticipantAdditions');
            return { content: MarkdownString.from(progress.markdownContent), kind: 'markdownContent' };
        }
        else if ('content' in progress) {
            if ('vulnerabilities' in progress && progress.vulnerabilities) {
                checkProposedApiEnabled(extension, 'chatParticipantAdditions');
                return { content: progress.content, vulnerabilities: progress.vulnerabilities, kind: 'vulnerability' };
            }
            if (typeof progress.content === 'string') {
                return { content: progress.content, kind: 'content' };
            }
            checkProposedApiEnabled(extension, 'chatParticipantAdditions');
            return { content: MarkdownString.from(progress.content), kind: 'markdownContent' };
        }
        else if ('documents' in progress) {
            return {
                documents: ( progress.documents.map(d => ({
                    uri: d.uri,
                    version: d.version,
                    ranges: ( d.ranges.map(r => Range.from(r)))
                }))),
                kind: 'usedContext'
            };
        }
        else if ('reference' in progress) {
            return {
                reference: 'uri' in progress.reference ?
                    {
                        uri: progress.reference.uri,
                        range: Range.from(progress.reference.range)
                    } : progress.reference,
                kind: 'reference'
            };
        }
        else if ('inlineReference' in progress) {
            return {
                inlineReference: 'uri' in progress.inlineReference ?
                    {
                        uri: progress.inlineReference.uri,
                        range: Range.from(progress.inlineReference.range)
                    } : progress.inlineReference,
                name: progress.title,
                kind: 'inlineReference'
            };
        }
        else if ('participant' in progress) {
            checkProposedApiEnabled(extension, 'chatParticipantAdditions');
            return { agentName: progress.participant, command: progress.command, kind: 'agentDetection' };
        }
        else if ('message' in progress) {
            return { content: MarkdownString.from(progress.message), kind: 'progressMessage' };
        }
        else {
            return undefined;
        }
    }
    ChatResponseProgress.from = from;
    function to(progress) {
        switch (progress.kind) {
            case 'markdownContent':
            case 'inlineReference':
            case 'treeData':
                return ChatResponseProgress.to(progress);
            case 'content':
                return { content: progress.content };
            case 'usedContext':
                return { documents: ( progress.documents.map(d => ({ uri: URI.revive(d.uri), version: d.version, ranges: ( d.ranges.map(r => Range.to(r))) }))) };
            case 'reference':
                return {
                    reference: isUriComponents(progress.reference) ?
                        URI.revive(progress.reference) :
                        Location.to(progress.reference)
                };
            case 'agentDetection':
                return undefined;
            case 'progressMessage':
                return { message: progress.content.value };
            case 'vulnerability':
                return { content: progress.content, vulnerabilities: progress.vulnerabilities };
            default:
                return undefined;
        }
    }
    ChatResponseProgress.to = to;
    function toProgressContent(progress, commandsConverter) {
        switch (progress.kind) {
            case 'markdownContent':
                return { content: progress.content.value };
            case 'inlineReference':
                return {
                    inlineReference: isUriComponents(progress.inlineReference) ?
                        URI.revive(progress.inlineReference) :
                        Location.to(progress.inlineReference),
                    title: progress.name
                };
            case 'command':
                return {
                    command: commandsConverter.fromInternal(progress.command) ?? { command: progress.command.id, title: progress.command.title },
                };
            default:
                return undefined;
        }
    }
    ChatResponseProgress.toProgressContent = toProgressContent;
})(ChatResponseProgress || (ChatResponseProgress = {})));
var ChatAgentRequest;
( (function(ChatAgentRequest) {
    function to(request) {
        return {
            prompt: request.message,
            command: request.command,
            variables: ( request.variables.variables.map(ChatAgentResolvedVariable.to))
        };
    }
    ChatAgentRequest.to = to;
})(ChatAgentRequest || (ChatAgentRequest = {})));
var ChatAgentResolvedVariable;
( (function(ChatAgentResolvedVariable) {
    function to(request) {
        return {
            name: request.name,
            range: [request.range.start, request.range.endExclusive],
            values: ( request.values.map(ChatVariable.to))
        };
    }
    ChatAgentResolvedVariable.to = to;
})(ChatAgentResolvedVariable || (ChatAgentResolvedVariable = {})));
var ChatAgentCompletionItem;
( (function(ChatAgentCompletionItem) {
    function from(item) {
        return {
            label: item.label,
            values: ( item.values.map(ChatVariable.from)),
            insertText: item.insertText,
            detail: item.detail,
            documentation: item.documentation,
        };
    }
    ChatAgentCompletionItem.from = from;
})(ChatAgentCompletionItem || (ChatAgentCompletionItem = {})));
var ChatAgentResult;
( (function(ChatAgentResult) {
    function to(result) {
        return {
            errorDetails: result.errorDetails,
            metadata: result.metadata,
        };
    }
    ChatAgentResult.to = to;
})(ChatAgentResult || (ChatAgentResult = {})));
var ChatAgentUserActionEvent;
( (function(ChatAgentUserActionEvent) {
    function to(result, event, commandsConverter) {
        if (event.action.kind === 'vote') {
            return;
        }
        const ehResult = ChatAgentResult.to(result);
        if (event.action.kind === 'command') {
            const commandAction = { kind: 'command', commandButton: ChatResponseProgress.toProgressContent(event.action.commandButton, commandsConverter) };
            return { action: commandAction, result: ehResult };
        }
        else if (event.action.kind === 'followUp') {
            const followupAction = { kind: 'followUp', followup: ChatFollowup.to(event.action.followup) };
            return { action: followupAction, result: ehResult };
        }
        else {
            return { action: event.action, result: ehResult };
        }
    }
    ChatAgentUserActionEvent.to = to;
})(ChatAgentUserActionEvent || (ChatAgentUserActionEvent = {})));
var TerminalQuickFix;
( (function(TerminalQuickFix) {
    function from(quickFix, converter, disposables) {
        if ('terminalCommand' in quickFix) {
            return { terminalCommand: quickFix.terminalCommand, shouldExecute: quickFix.shouldExecute };
        }
        if ('uri' in quickFix) {
            return { uri: quickFix.uri };
        }
        return converter.toInternal(quickFix, disposables);
    }
    TerminalQuickFix.from = from;
})(TerminalQuickFix || (TerminalQuickFix = {})));
var DebugTreeItem;
( (function(DebugTreeItem) {
    function from(item, id) {
        return {
            id,
            label: item.label,
            description: item.description,
            canEdit: item.canEdit,
            collapsibleState: ((item.collapsibleState || 0) ),
            contextValue: item.contextValue,
        };
    }
    DebugTreeItem.from = from;
})(DebugTreeItem || (DebugTreeItem = {})));
export { CallHierarchyIncomingCall, CallHierarchyItem, CallHierarchyOutgoingCall, ChatAgentCompletionItem, ChatAgentRequest, ChatAgentResolvedVariable, ChatAgentResult, ChatAgentUserActionEvent, ChatFollowup, ChatInlineFollowup, ChatResponseAnchorPart, ChatResponseCommandButtonPart, ChatResponseFilesPart, ChatResponseMarkdownPart, ChatResponsePart, ChatResponseProgress, ChatResponseProgressPart, ChatResponseReferencePart, ChatVariable, ChatVariableLevel, CodeActionTriggerKind, Color, ColorPresentation, CompletionContext, CompletionItem, CompletionItemKind, CompletionItemTag, CompletionTriggerKind, DataTransfer, DataTransferItem, DebugTreeItem, DecorationRangeBehavior, DecorationRenderOptions, DefinitionLink, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag, DocumentHighlight, DocumentLink, DocumentSelector, DocumentSymbol, EndOfLine, EvaluatableExpression, FoldingRange, FoldingRangeKind, GlobPattern, Hover, InlayHint, InlayHintKind, InlayHintLabelPart, InlineValue, InlineValueContext, InteractiveEditorResponseFeedbackKind, LanguageModelMessage, LanguageSelector, Location, MappedEditsContext, MarkdownString, MultiDocumentHighlight, NotebookCellData, NotebookCellExecutionState, NotebookCellExecutionSummary, NotebookCellKind, NotebookCellOutput, NotebookCellOutputItem, NotebookData, NotebookDocumentContentOptions, NotebookExclusiveDocumentPattern, NotebookKernelSourceAction, NotebookRange, NotebookRendererScript, NotebookStatusBarItem, ParameterInformation, Position, ProgressLocation, Range, Selection, SelectionRange, SignatureHelp, SignatureInformation, SymbolKind, SymbolTag, TerminalQuickFix, TestCoverage, TestItem, TestMessage, TestResults, TestTag, TextDocumentSaveReason, TextEdit, TextEditorLineNumbersStyle, TextEditorOpenOptions, ThemableDecorationAttachmentRenderOptions, ThemableDecorationRenderOptions, TokenType, TypeHierarchyItem, ViewBadge, ViewColumn, WorkspaceEdit, WorkspaceSymbol, fromRangeOrRangeWithMessage, isDecorationOptionsArr, location, pathOrURIToURI };
