Skip to content

Commit

Permalink
feat(language-client): support coc.preferences.enableMarkdown
Browse files Browse the repository at this point in the history
Make it possible to diable markdown document of language server.

Related #2308
  • Loading branch information
chemzqm committed Oct 16, 2020
1 parent 92daf08 commit 60e5ba2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
5 changes: 5 additions & 0 deletions data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,11 @@
"description": "Use prompt buffer in float window for user input, works on neovim >= 0.5.0 only.",
"default": true
},
"coc.preferences.enableMarkdown": {
"type": "boolean",
"description": "Tell the language server that markdown text format is supported, note that markdown text may not rendered as expected.",
"default": true
},
"coc.source.around.enable": {
"type": "boolean",
"default": true
Expand Down
6 changes: 6 additions & 0 deletions doc/coc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,12 @@ Built-in configurations:~
neovim only.
Default: `true`

"coc.preferences.enableMarkdown":~

Tell the language server that markdown text format is supported,
note that you may have additional escaped characters for markdown
text.

*coc-config-cursors*
"cursors.cancelKey":~

Expand Down
38 changes: 21 additions & 17 deletions src/language-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,9 @@ export interface DynamicFeature<T> {
}

export interface NotificationFeature<T extends Function> {
/**
* Triggers the corresponding RPC method.
*/
/**
* Triggers the corresponding RPC method.
*/
getProvider(document: TextDocument): { send: T }
}

Expand Down Expand Up @@ -1656,9 +1656,9 @@ interface TextDocumentFeatureRegistration<RO, PR> {
}

export interface TextDocumentProviderFeature<T> {
/**
* Triggers the corresponding RPC method.
*/
/**
* Triggers the corresponding RPC method.
*/
getProvider(textDocument: TextDocument): T
}

Expand Down Expand Up @@ -1686,8 +1686,7 @@ export abstract class TextDocumentFeature<
public register(message: RPCMessageType, data: RegistrationData<RO>): void {
if (message.method !== this.messages.method) {
throw new Error(
`Register called on wrong feature. Requested ${
message.method
`Register called on wrong feature. Requested ${message.method
} but reached feature ${this.messages.method}`
)
}
Expand Down Expand Up @@ -1816,7 +1815,7 @@ class CompletionItemFeature extends TextDocumentFeature<CompletionOptions, Compl
completion.completionItem = {
snippetSupport,
commitCharactersSupport: true,
documentationFormat: [MarkupKind.Markdown, MarkupKind.PlainText],
documentationFormat: this._client.supporedMarkupKind,
deprecatedSupport: true,
preselectSupport: true,
// tagSupport: { valueSet: [CompletionItemTag.Deprecated] },
Expand Down Expand Up @@ -1911,7 +1910,7 @@ class HoverFeature extends TextDocumentFeature<
'hover'
)!
hoverCapability.dynamicRegistration = true
hoverCapability.contentFormat = [MarkupKind.Markdown, MarkupKind.PlainText]
hoverCapability.contentFormat = this._client.supporedMarkupKind
}

public initialize(
Expand Down Expand Up @@ -1968,7 +1967,7 @@ class SignatureHelpFeature extends TextDocumentFeature<
config.dynamicRegistration = true
// config.contextSupport = true // TODO context and meta support
config.signatureInformation = {
documentationFormat: [MarkupKind.Markdown, MarkupKind.PlainText],
documentationFormat: this._client.supporedMarkupKind,
parameterInformation: {
labelOffsetSupport: true
}
Expand Down Expand Up @@ -3039,6 +3038,7 @@ class OnReady {
export abstract class BaseLanguageClient {
private _id: string
private _name: string
private _markdownSupport: boolean
private _clientOptions: ResolvedClientOptions

protected _state: ClientState
Expand Down Expand Up @@ -3123,9 +3123,16 @@ export abstract class BaseLanguageClient {
}
}
this._syncedDocuments = new Map<string, TextDocument>()
let preferences = workspace.getConfiguration('coc.preferences')
this._markdownSupport = preferences.get('enableMarkdown', true)
this.registerBuiltinFeatures()
}

public get supporedMarkupKind(): MarkupKind[] {
if (this._markdownSupport) return [MarkupKind.Markdown, MarkupKind.PlainText]
return [MarkupKind.PlainText]
}

private get state(): ClientState {
return this._state
}
Expand Down Expand Up @@ -3217,8 +3224,7 @@ export abstract class BaseLanguageClient {
this._resolvedConnection!.onRequest(type, handler)
} catch (error) {
this.error(
`Registering request handler ${
Is.string(type) ? type : type.method
`Registering request handler ${Is.string(type) ? type : type.method
} failed.`,
error
)
Expand Down Expand Up @@ -3256,8 +3262,7 @@ export abstract class BaseLanguageClient {
this._resolvedConnection!.onNotification(type, handler)
} catch (error) {
this.error(
`Registering notification handler ${
Is.string(type) ? type : type.method
`Registering notification handler ${Is.string(type) ? type : type.method
} failed.`,
error
)
Expand Down Expand Up @@ -3342,8 +3347,7 @@ export abstract class BaseLanguageClient {
private data2String(data: any): string {
if (data instanceof ResponseError) {
const responseError = data as ResponseError<any>
return ` Message: ${responseError.message}\n Code: ${
responseError.code
return ` Message: ${responseError.message}\n Code: ${responseError.code
} ${responseError.data ? '\n' + responseError.data.toString() : ''}`
}
if (data instanceof Error) {
Expand Down

0 comments on commit 60e5ba2

Please sign in to comment.