From 91f8603fcd1ee66f60caae1bb2277a13e027aa33 Mon Sep 17 00:00:00 2001 From: Heyward Fann Date: Thu, 25 Aug 2022 18:37:05 +0800 Subject: [PATCH] feat: format signatureHelp close #796 --- src/index.ts | 5 +++-- src/middleware.ts | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1c6e1d6f..08acb70a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,7 +28,7 @@ import { TypeInlayHintsProvider } from './features/inlayHints'; import { sortImports } from './features/isort'; import { LinterProvider } from './features/lintting'; import { addImport, extractMethod, extractVariable } from './features/refactor'; -import { configuration, handleDiagnostics, provideCompletionItem, provideHover, resolveCompletionItem } from './middleware'; +import { configuration, handleDiagnostics, provideCompletionItem, provideHover, provideSignatureHelp, resolveCompletionItem } from './middleware'; const defaultHeapSize = 3072; @@ -115,8 +115,9 @@ export async function activate(context: ExtensionContext): Promise { configuration, }, provideHover, - handleDiagnostics, + provideSignatureHelp, provideCompletionItem, + handleDiagnostics, resolveCompletionItem, }, }; diff --git a/src/middleware.ts b/src/middleware.ts index 5e4015a8..6cc1c7d2 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -11,7 +11,9 @@ import { Position, ProvideCompletionItemsSignature, ProvideHoverSignature, + ProvideSignatureHelpSignature, ResolveCompletionItemSignature, + SignatureHelpContext, workspace, } from 'coc.nvim'; import { PythonSettings } from './configSettings'; @@ -121,6 +123,25 @@ export async function provideHover(document: LinesTextDocument, position: Positi return hover; } +export async function provideSignatureHelp( + document: LinesTextDocument, + position: Position, + context: SignatureHelpContext, + token: CancellationToken, + next: ProvideSignatureHelpSignature +) { + const sign = await next(document, position, context, token); + if (sign && sign.signatures.length) { + sign.signatures.forEach((info) => { + if (info.documentation && typeof info.documentation === 'object' && info.documentation.kind === 'markdown') { + info.documentation.value = info.documentation.value.replace(/ /g, ' '); + } + }); + } + + return sign; +} + export async function handleDiagnostics(uri: string, diagnostics: Diagnostic[], next: HandleDiagnosticsSignature) { next( uri,