Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions internal/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,18 @@ func getCapabilitiesWithDefaults(capabilities *lsproto.ClientCapabilities) *lspr
if capabilitiesWithDefaults.TextDocument.Hover == nil {
capabilitiesWithDefaults.TextDocument.Hover = defaultHoverCapabilities
}
if capabilitiesWithDefaults.TextDocument.SignatureHelp == nil {
capabilitiesWithDefaults.TextDocument.SignatureHelp = &lsproto.SignatureHelpClientCapabilities{
SignatureInformation: &lsproto.ClientSignatureInformationOptions{
DocumentationFormat: &[]lsproto.MarkupKind{lsproto.MarkupKindMarkdown, lsproto.MarkupKindPlainText},
ParameterInformation: &lsproto.ClientSignatureParameterInformationOptions{
LabelOffsetSupport: ptrTrue,
},
ActiveParameterSupport: ptrTrue,
},
ContextSupport: ptrTrue,
Comment on lines +304 to +309
Copy link
Member Author

@jakebailey jakebailey Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not actually checking these correctly currently (different PR).

}
}
return &capabilitiesWithDefaults
}

Expand Down
40 changes: 33 additions & 7 deletions internal/ls/signaturehelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (l *LanguageService) ProvideSignatureHelp(
position lsproto.Position,
context *lsproto.SignatureHelpContext,
clientOptions *lsproto.SignatureHelpClientCapabilities,
docFormat lsproto.MarkupKind,
) (lsproto.SignatureHelpResponse, error) {
program, sourceFile := l.getProgramAndFile(documentURI)
items := l.GetSignatureHelpItems(
Expand All @@ -52,7 +53,8 @@ func (l *LanguageService) ProvideSignatureHelp(
program,
sourceFile,
context,
clientOptions)
clientOptions,
docFormat)
return lsproto.SignatureHelpOrNull{SignatureHelp: items}, nil
}

Expand All @@ -63,6 +65,7 @@ func (l *LanguageService) GetSignatureHelpItems(
sourceFile *ast.SourceFile,
context *lsproto.SignatureHelpContext,
clientOptions *lsproto.SignatureHelpClientCapabilities,
docFormat lsproto.MarkupKind,
) *lsproto.SignatureHelp {
typeChecker, done := program.GetTypeCheckerForFile(ctx, sourceFile)
defer done()
Expand Down Expand Up @@ -140,7 +143,7 @@ func (l *LanguageService) GetSignatureHelpItems(

// return typeChecker.runWithCancellationToken(cancellationToken, typeChecker =>
if candidateInfo.candidateInfo != nil {
return createSignatureHelpItems(candidateInfo.candidateInfo.candidates, candidateInfo.candidateInfo.resolvedSignature, argumentInfo, sourceFile, typeChecker, onlyUseSyntacticOwners, clientOptions)
return l.createSignatureHelpItems(candidateInfo.candidateInfo.candidates, candidateInfo.candidateInfo.resolvedSignature, argumentInfo, sourceFile, typeChecker, onlyUseSyntacticOwners, clientOptions, docFormat)
}
return createTypeHelpItems(candidateInfo.typeInfo, argumentInfo, sourceFile, clientOptions, typeChecker)
}
Expand Down Expand Up @@ -202,7 +205,7 @@ func getTypeHelpItem(symbol *ast.Symbol, typeParameter []*checker.Type, enclosin
}
}

func createSignatureHelpItems(candidates []*checker.Signature, resolvedSignature *checker.Signature, argumentInfo *argumentListInfo, sourceFile *ast.SourceFile, c *checker.Checker, useFullPrefix bool, clientOptions *lsproto.SignatureHelpClientCapabilities) *lsproto.SignatureHelp {
func (l *LanguageService) createSignatureHelpItems(candidates []*checker.Signature, resolvedSignature *checker.Signature, argumentInfo *argumentListInfo, sourceFile *ast.SourceFile, c *checker.Checker, useFullPrefix bool, clientOptions *lsproto.SignatureHelpClientCapabilities, docFormat lsproto.MarkupKind) *lsproto.SignatureHelp {
enclosingDeclaration := getEnclosingDeclarationFromInvocation(argumentInfo.invocation)
if enclosingDeclaration == nil {
return nil
Expand All @@ -223,7 +226,7 @@ func createSignatureHelpItems(candidates []*checker.Signature, resolvedSignature
}
items := make([][]signatureInformation, len(candidates))
for i, candidateSignature := range candidates {
items[i] = getSignatureHelpItem(candidateSignature, argumentInfo.isTypeParameterList, callTargetDisplayParts.String(), enclosingDeclaration, sourceFile, c)
items[i] = l.getSignatureHelpItem(candidateSignature, argumentInfo.isTypeParameterList, callTargetDisplayParts.String(), enclosingDeclaration, sourceFile, c, docFormat)
}

selectedItemIndex := 0
Expand Down Expand Up @@ -262,9 +265,18 @@ func createSignatureHelpItems(candidates []*checker.Signature, resolvedSignature
for j, param := range item.Parameters {
parameters[j] = param.parameterInfo
}
var documentation *lsproto.StringOrMarkupContent
if item.Documentation != nil {
documentation = &lsproto.StringOrMarkupContent{
MarkupContent: &lsproto.MarkupContent{
Kind: docFormat,
Value: *item.Documentation,
},
}
}
signatureInformation[i] = &lsproto.SignatureInformation{
Label: item.Label,
Documentation: nil,
Documentation: documentation,
Parameters: &parameters,
}
}
Expand All @@ -291,7 +303,7 @@ func createSignatureHelpItems(candidates []*checker.Signature, resolvedSignature
return help
}

func getSignatureHelpItem(candidate *checker.Signature, isTypeParameterList bool, callTargetSymbol string, enclosingDeclaration *ast.Node, sourceFile *ast.SourceFile, c *checker.Checker) []signatureInformation {
func (l *LanguageService) getSignatureHelpItem(candidate *checker.Signature, isTypeParameterList bool, callTargetSymbol string, enclosingDeclaration *ast.Node, sourceFile *ast.SourceFile, c *checker.Checker, docFormat lsproto.MarkupKind) []signatureInformation {
var infos []*signatureHelpItemInfo
if isTypeParameterList {
infos = itemInfoForTypeParameters(candidate, c, enclosingDeclaration, sourceFile)
Expand All @@ -301,6 +313,20 @@ func getSignatureHelpItem(candidate *checker.Signature, isTypeParameterList bool

suffixDisplayParts := returnTypeToDisplayParts(candidate, c)

// Generate documentation from the signature's declaration
var documentation *string
if declaration := candidate.Declaration(); declaration != nil {
if jsdoc := getJSDocOrTag(declaration); jsdoc != nil {
isMarkdown := docFormat == lsproto.MarkupKindMarkdown
var b strings.Builder
l.writeComments(&b, c, jsdoc.Comments(), isMarkdown)
if b.Len() > 0 {
docString := b.String()
documentation = &docString
}
}
}

result := make([]signatureInformation, len(infos))
for i, info := range infos {
var display strings.Builder
Expand All @@ -309,7 +335,7 @@ func getSignatureHelpItem(candidate *checker.Signature, isTypeParameterList bool
display.WriteString(suffixDisplayParts)
result[i] = signatureInformation{
Label: display.String(),
Documentation: nil,
Documentation: documentation,
Parameters: info.parameters,
IsVariadic: info.isVariadic,
}
Expand Down
16 changes: 16 additions & 0 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ func (s *Server) handleSignatureHelp(ctx context.Context, languageService *ls.La
params.Position,
params.Context,
s.initializeParams.Capabilities.TextDocument.SignatureHelp,
getSignatureHelpDocumentationFormat(s.initializeParams),
)
}

Expand Down Expand Up @@ -1021,3 +1022,18 @@ func getHoverContentFormat(params *lsproto.InitializeParams) lsproto.MarkupKind
// Return the first (most preferred) format
return formats[0]
}

func getSignatureHelpDocumentationFormat(params *lsproto.InitializeParams) lsproto.MarkupKind {
if params == nil || params.Capabilities.TextDocument == nil || params.Capabilities.TextDocument.SignatureHelp == nil ||
params.Capabilities.TextDocument.SignatureHelp.SignatureInformation == nil ||
params.Capabilities.TextDocument.SignatureHelp.SignatureInformation.DocumentationFormat == nil {
// Default to plaintext if no preference specified
return lsproto.MarkupKindPlainText
}
formats := *params.Capabilities.TextDocument.SignatureHelp.SignatureInformation.DocumentationFormat
if len(formats) == 0 {
return lsproto.MarkupKindPlainText
}
// Return the first (most preferred) format
return formats[0]
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// ^
// | ----------------------------------------------------------------------
// | pathFilter(**basePath: String**, pattern: String, type: String, options: Object): any[]
// | Filters a path based on a regexp or glob pattern.
// | ----------------------------------------------------------------------
[
{
Expand All @@ -31,6 +32,10 @@
"signatures": [
{
"label": "pathFilter(basePath: String, pattern: String, type: String, options: Object): any[]",
"documentation": {
"kind": "markdown",
"value": "Filters a path based on a regexp or glob pattern."
},
"parameters": [
{
"label": "basePath: String"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// ^
// | ----------------------------------------------------------------------
// | find(**l: unknown[]**, x: unknown): unknown
// | Find an item
// | ----------------------------------------------------------------------
[
{
Expand All @@ -29,6 +30,10 @@
"signatures": [
{
"label": "find(l: unknown[], x: unknown): unknown",
"documentation": {
"kind": "markdown",
"value": "Find an item"
},
"parameters": [
{
"label": "l: unknown[]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// ^
// | ----------------------------------------------------------------------
// | c3(): c3
// | Constructor comment
// | ----------------------------------------------------------------------
// var i3_c = c3;
// /** Class comment*/
Expand All @@ -30,6 +31,7 @@
// ^
// | ----------------------------------------------------------------------
// | c4(): c4
// | Constructor comment
// | ----------------------------------------------------------------------
// var i4_c = c4;
// /** Class with statics*/
Expand All @@ -54,6 +56,7 @@
// ^
// | ----------------------------------------------------------------------
// | c6(): c6
// | constructor comment
// | ----------------------------------------------------------------------
// var i6_c = c6;
//
Expand All @@ -69,6 +72,7 @@
// ^
// | ----------------------------------------------------------------------
// | a(**a: string**): a
// | constructor for a
// | ----------------------------------------------------------------------
// module m {
// export module m2 {
Expand Down Expand Up @@ -117,6 +121,10 @@
"signatures": [
{
"label": "c3(): c3",
"documentation": {
"kind": "markdown",
"value": "Constructor comment"
},
"parameters": []
}
],
Expand All @@ -138,6 +146,10 @@
"signatures": [
{
"label": "c4(): c4",
"documentation": {
"kind": "markdown",
"value": "Constructor comment"
},
"parameters": []
}
],
Expand Down Expand Up @@ -180,6 +192,10 @@
"signatures": [
{
"label": "c6(): c6",
"documentation": {
"kind": "markdown",
"value": "constructor comment"
},
"parameters": []
}
],
Expand All @@ -201,6 +217,10 @@
"signatures": [
{
"label": "a(a: string): a",
"documentation": {
"kind": "markdown",
"value": "constructor for a"
},
"parameters": [
{
"label": "a: string"
Expand Down
Loading