Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed markdown conversion #103

Merged
merged 1 commit into from
Aug 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 45 additions & 64 deletions src/monaco-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,35 +153,33 @@ export class MonacoToProtocolConverter {
if (item.command) { result.command = this.asCommand(item.command); }
// TODO if (item.preselect === true || item.preselect === false) { result.preselect = item.preselect; }
if (protocolItem) {
if (protocolItem.data !== undefined) {
result.data = protocolItem.data;
}
if (protocolItem.deprecated === true || protocolItem.deprecated === false) {
result.deprecated = protocolItem.deprecated;
}
}
return result;
}

protected asCompletionItemKind(value: monaco.languages.CompletionItemKind, original: CompletionItemKind | undefined): CompletionItemKind {
if (original !== undefined) {
return original;
}
return value + 1 as CompletionItemKind;
}
if (protocolItem.data !== undefined) {
result.data = protocolItem.data;
}
if (protocolItem.deprecated === true || protocolItem.deprecated === false) {
result.deprecated = protocolItem.deprecated;
}
}
return result;
}

protected asCompletionItemKind(value: monaco.languages.CompletionItemKind, original: CompletionItemKind | undefined): CompletionItemKind {
if (original !== undefined) {
return original;
}
return value + 1 as CompletionItemKind;
}

protected asDocumentation(format: string, documentation: string | monaco.IMarkdownString): string | MarkupContent {
switch (format) {
case '$string':
return documentation as string;
case MarkupKind.PlainText:
return { kind: format, value: documentation as string };
case MarkupKind.Markdown:
return { kind: format, value: (documentation as monaco.IMarkdownString).value };
default:
return `Unsupported Markup content received. Kind is: ${format}`;
}
}
switch (format) {
case MarkupKind.PlainText:
return { kind: format, value: documentation as string };
case MarkupKind.Markdown:
return { kind: format, value: (documentation as monaco.IMarkdownString).value };
default:
return `Unsupported Markup content received. Kind is: ${format}`;
}
}

protected fillPrimaryInsertText(target: CompletionItem, source: ProtocolCompletionItem): void {
let format: InsertTextFormat = InsertTextFormat.PlainText;
Expand Down Expand Up @@ -299,11 +297,11 @@ export class MonacoToProtocolConverter {

asCodeLens(item: monaco.languages.ICodeLensSymbol): CodeLens {
let result = CodeLens.create(this.asRange(item.range));
if (item.command) { result.command = this.asCommand(item.command); }
if (ProtocolCodeLens.is(item)) {
if (item.data) { result.data = item.data };
}
return result;
if (item.command) { result.command = this.asCommand(item.command); }
if (ProtocolCodeLens.is(item)) {
if (item.data) { result.data = item.data };
}
return result;
}

asFormattingOptions(options: monaco.languages.FormattingOptions): FormattingOptions {
Expand Down Expand Up @@ -349,12 +347,12 @@ export class MonacoToProtocolConverter {
}

asDocumentLink(item: monaco.languages.ILink): DocumentLink {
let result = DocumentLink.create(this.asRange(item.range));
if (item.url) { result.target = item.url; }
if (ProtocolDocumentLink.is(item) && item.data) {
result.data = item.data;
}
return result;
let result = DocumentLink.create(this.asRange(item.range));
if (item.url) { result.target = item.url; }
if (ProtocolDocumentLink.is(item) && item.data) {
result.data = item.data;
}
return result;
}
}

Expand Down Expand Up @@ -468,7 +466,7 @@ export class ProtocolToMonacoConverter {
asCommand(command: Command): monaco.languages.Command;
asCommand(command: undefined): undefined;
asCommand(command: Command | undefined): monaco.languages.Command | undefined;
asCommand(command: Command |  undefined): monaco.languages.Command | undefined {
asCommand(command: Command | undefined): monaco.languages.Command | undefined {
if (!command) {
return undefined;
}
Expand Down Expand Up @@ -638,22 +636,6 @@ export class ProtocolToMonacoConverter {
};
}

asIMarkdownString(content: MarkedString | MarkupContent): monaco.IMarkdownString {
if (typeof content === 'string') {
return {
value: content
}
}
if ('kind' in content) {
const { value } = content;
return { value };
}
const { language, value } = content;
return {
value: '```' + language + '\n' + value + '\n```'
};
}

asHoverContent(contents: MarkedString | MarkedString[] | MarkupContent): monaco.IMarkdownString[] {
if (Array.isArray(contents)) {
return contents.map(content => this.asMarkdownString(content));
Expand All @@ -665,18 +647,17 @@ export class ProtocolToMonacoConverter {
if (Is.string(value)) {
return value;
}
if (value.kind === MarkupKind.PlainText) {
return value.value;
}
return this.asMarkdownString(value);
}

asMarkdownString(content: MarkedString | MarkupContent): monaco.IMarkdownString {
if (MarkupContent.is(content)) {
const value = content.value;
if (content.kind === MarkupKind.Markdown) {
return {
value: '```\n' + value + '\n```'
};
}
return { value };
return {
value: content.value
};
}
if (Is.string(content)) {
return { value: content };
Expand All @@ -702,8 +683,8 @@ export class ProtocolToMonacoConverter {

asDiagnostics(diagnostics: undefined): undefined;
asDiagnostics(diagnostics: Diagnostic[]): monaco.editor.IMarkerData[];
asDiagnostics(diagnostics: Diagnostic[] |  undefined): monaco.editor.IMarkerData[] |  undefined;
asDiagnostics(diagnostics: Diagnostic[] |  undefined): monaco.editor.IMarkerData[] |  undefined {
asDiagnostics(diagnostics: Diagnostic[] | undefined): monaco.editor.IMarkerData[] | undefined;
asDiagnostics(diagnostics: Diagnostic[] | undefined): monaco.editor.IMarkerData[] | undefined {
if (!diagnostics) {
return undefined;
}
Expand Down