Skip to content

Commit

Permalink
Merge pull request #199 from TypeFox/bumpMonacoVersion
Browse files Browse the repository at this point in the history
Bump monaco version
  • Loading branch information
akosyakov authored Mar 19, 2020
2 parents bc8b38c + 6590ed7 commit 95c9925
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 112 deletions.
8 changes: 4 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "TypeFox GmbH (http://www.typefox.io)",
"license": "MIT",
"engines": {
"vscode": "^1.33.0"
"vscode": "^1.41.0"
},
"repository": {
"type": "git",
Expand All @@ -18,9 +18,9 @@
"typings": "./lib/index",
"dependencies": {
"glob-to-regexp": "^0.3.0",
"vscode-jsonrpc": "^4.1.0-next",
"vscode-languageclient": "^5.3.0-next",
"vscode-uri": "^1.0.5"
"vscode-jsonrpc": "^5.0.0",
"vscode-languageclient": "^6.0.0",
"vscode-uri": "^1.0.8"
},
"scripts": {
"prepare": "yarn run clean && yarn run compile",
Expand Down
65 changes: 53 additions & 12 deletions client/src/monaco-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
CompletionParams, CompletionContext, CompletionTriggerKind,
InsertTextFormat, Range, Diagnostic, CompletionItemKind,
Hover, SignatureHelp, SignatureInformation, ParameterInformation,
Definition, Location, DocumentHighlight, DocumentHighlightKind,
Definition, DefinitionLink, Location, LocationLink, DocumentHighlight, DocumentHighlightKind,
SymbolInformation, DocumentSymbolParams, CodeActionContext, DiagnosticSeverity,
Command, CodeLens, FormattingOptions, TextEdit, WorkspaceEdit, DocumentLinkParams, DocumentLink,
MarkedString, MarkupContent, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind,
Expand Down Expand Up @@ -56,6 +56,12 @@ export namespace ProtocolCompletionItem {
}
}

type RangeReplace = { insert: monaco.IRange; replace: monaco.IRange}

function isRangeReplace(v: Partial<monaco.IRange> | RangeReplace) : v is RangeReplace {
return (v as RangeReplace).insert !== undefined;
}

export class MonacoToProtocolConverter {
asPosition(lineNumber: undefined | null, column: undefined | null): {};
asPosition(lineNumber: number, column: undefined | null): Pick<Position, 'line'>;
Expand All @@ -75,21 +81,28 @@ export class MonacoToProtocolConverter {
asRange(range: monaco.IRange): Range;
asRange(range: monaco.IRange | undefined): Range | undefined;
asRange(range: monaco.IRange | null): Range | null;
asRange(range: monaco.IRange | { insert: monaco.IRange; replace: monaco.IRange}) : Range;
asRange(range: Partial<monaco.IRange>): RecursivePartial<Range>;
asRange(range: Partial<monaco.IRange> | undefined): RecursivePartial<Range> | undefined;
asRange(range: Partial<monaco.IRange> | null): RecursivePartial<Range> | null;
asRange(range: Partial<monaco.IRange> | undefined | null): RecursivePartial<Range> | undefined | null {
asRange(range: Partial<monaco.IRange> | undefined | null | RangeReplace): RecursivePartial<Range> | undefined | null {
if (range === undefined) {
return undefined;
}
if (range === null) {
return null;
}
const start = this.asPosition(range.startLineNumber, range.startColumn);
const end = this.asPosition(range.endLineNumber, range.endColumn);
return {
start, end
};

if (isRangeReplace(range)) {
return this.asRange(range.insert);

} else {
const start = this.asPosition(range.startLineNumber, range.startColumn);
const end = this.asPosition(range.endLineNumber, range.endColumn);
return {
start, end
};
}
}

asTextDocumentIdentifier(model: IReadOnlyModel): TextDocumentIdentifier {
Expand Down Expand Up @@ -679,14 +692,23 @@ export class ProtocolToMonacoConverter {
}

asDefinitionResult(item: Definition): monaco.languages.Definition;
asDefinitionResult(item: DefinitionLink[]): monaco.languages.Definition;
asDefinitionResult(item: undefined | null): undefined;
asDefinitionResult(item: Definition | undefined | null): monaco.languages.Definition | undefined;
asDefinitionResult(item: Definition | undefined | null): monaco.languages.Definition | undefined {
asDefinitionResult(item: Definition | DefinitionLink[] | undefined | null): monaco.languages.Definition | undefined;
asDefinitionResult(item: Definition | DefinitionLink[] | undefined | null): monaco.languages.Definition | undefined {
if (!item) {
return undefined;
}
if (Is.array(item)) {
return item.map((location) => this.asLocation(location));
if (item.length == 0) {
return undefined;
} else if (LocationLink.is(item[0])) {
let links: LocationLink[] = item as LocationLink[];
return links.map((location) => this.asLocationLink(location));
} else {
let locations: Location[] = item as Location[];
return locations.map((location) => this.asLocation(location));
}
} else {
return this.asLocation(item);
}
Expand All @@ -706,6 +728,24 @@ export class ProtocolToMonacoConverter {
}
}

asLocationLink(item: undefined | null): undefined;
asLocationLink(item: ls.LocationLink): monaco.languages.LocationLink;
asLocationLink(item: ls.LocationLink | undefined | null): monaco.languages.LocationLink | undefined {
if (!item) {
return undefined;
}
let result: monaco.languages.LocationLink = {
uri: monaco.Uri.parse(item.targetUri),
range: this.asRange(item.targetSelectionRange)!, // See issue: https://github.com/Microsoft/vscode/issues/58649
originSelectionRange: this.asRange(item.originSelectionRange),
targetSelectionRange: this.asRange(item.targetSelectionRange)
};
if (!result.targetSelectionRange) {
throw new Error(`targetSelectionRange must not be undefined or null`);
}
return result;
}

asSignatureHelpResult(item: undefined | null): undefined;
asSignatureHelpResult(item: SignatureHelp): monaco.languages.SignatureHelpResult;
asSignatureHelpResult(item: SignatureHelp | undefined | null): monaco.languages.SignatureHelpResult | undefined;
Expand Down Expand Up @@ -882,7 +922,7 @@ export class ProtocolToMonacoConverter {
}
}

asCompletionItem(item: CompletionItem, defaultRange: monaco.IRange): ProtocolCompletionItem {
asCompletionItem(item: CompletionItem, defaultRange: monaco.IRange | RangeReplace): ProtocolCompletionItem {
const result = <ProtocolCompletionItem>{ label: item.label };
if (item.detail) { result.detail = item.detail; }
if (item.documentation) {
Expand Down Expand Up @@ -952,7 +992,8 @@ export class ProtocolToMonacoConverter {
return [CompletionItemKind.Text, value];
}

asCompletionInsertText(item: CompletionItem, defaultRange: monaco.IRange): { insertText: string, range: monaco.IRange, fromEdit: boolean, isSnippet: boolean } {
asCompletionInsertText(item: CompletionItem, defaultRange: monaco.IRange | RangeReplace)
: { insertText: string, range: monaco.IRange | RangeReplace, fromEdit: boolean, isSnippet: boolean } {
const isSnippet = item.insertTextFormat === InsertTextFormat.Snippet;
if (item.textEdit) {
const range = this.asRange(item.textEdit.range);
Expand Down
2 changes: 1 addition & 1 deletion client/src/monaco-language-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class MonacoLanguageClient extends BaseLanguageClient {
return this.connectionProvider.get(errorHandler, closeHandler, this.outputChannel);
}

protected createMessageTransports(encoding: string): Thenable<MessageTransports> {
protected createMessageTransports(encoding: string): Promise<MessageTransports> {
throw new Error('Unsupported');
}

Expand Down
8 changes: 8 additions & 0 deletions client/src/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ export enum SignatureHelpTriggerKind {
ContentChange = 3
}

// runtime support
export enum VsCodeDiagnosticSeverity {
Error = 0,
Warning = 1,
Information = 2,
Hint = 3
}

export interface SignatureHelpContext {
readonly triggerKind: SignatureHelpTriggerKind;
readonly triggerCharacter?: string;
Expand Down
Loading

0 comments on commit 95c9925

Please sign in to comment.