Skip to content

Commit

Permalink
feat: format signatureHelp
Browse files Browse the repository at this point in the history
  • Loading branch information
fannheyward committed Aug 25, 2022
1 parent a5af69c commit 91f8603
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -115,8 +115,9 @@ export async function activate(context: ExtensionContext): Promise<void> {
configuration,
},
provideHover,
handleDiagnostics,
provideSignatureHelp,
provideCompletionItem,
handleDiagnostics,
resolveCompletionItem,
},
};
Expand Down
21 changes: 21 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
Position,
ProvideCompletionItemsSignature,
ProvideHoverSignature,
ProvideSignatureHelpSignature,
ResolveCompletionItemSignature,
SignatureHelpContext,
workspace,
} from 'coc.nvim';
import { PythonSettings } from './configSettings';
Expand Down Expand Up @@ -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(/&nbsp;/g, ' ');
}
});
}

return sign;
}

export async function handleDiagnostics(uri: string, diagnostics: Diagnostic[], next: HandleDiagnosticsSignature) {
next(
uri,
Expand Down

0 comments on commit 91f8603

Please sign in to comment.