Skip to content
Merged
Show file tree
Hide file tree
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
158 changes: 63 additions & 95 deletions internal/ls/completions.go

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions internal/ls/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ func (l *LanguageService) ProvideDefinition(
ctx context.Context,
documentURI lsproto.DocumentUri,
position lsproto.Position,
clientSupportsLink bool,
) (lsproto.DefinitionResponse, error) {
caps := lsproto.GetClientCapabilities(ctx)
clientSupportsLink := caps.TextDocument.Definition.LinkSupport

program, file := l.getProgramAndFile(documentURI)
node := astnav.GetTouchingPropertyName(file, int(l.converters.LineAndCharacterToPosition(file, position)))
if node.Kind == ast.KindSourceFile {
Expand Down Expand Up @@ -68,8 +70,10 @@ func (l *LanguageService) ProvideTypeDefinition(
ctx context.Context,
documentURI lsproto.DocumentUri,
position lsproto.Position,
clientSupportsLink bool,
) (lsproto.DefinitionResponse, error) {
) (lsproto.TypeDefinitionResponse, error) {
caps := lsproto.GetClientCapabilities(ctx)
clientSupportsLink := caps.TextDocument.TypeDefinition.LinkSupport

program, file := l.getProgramAndFile(documentURI)
node := astnav.GetTouchingPropertyName(file, int(l.converters.LineAndCharacterToPosition(file, position)))
if node.Kind == ast.KindSourceFile {
Expand Down Expand Up @@ -279,8 +283,3 @@ func getDeclarationsFromType(t *checker.Type) []*ast.Node {
}
return result
}

func clientSupportsLink(clientCapabilities *lsproto.DefinitionClientCapabilities) bool {
return clientCapabilities != nil &&
ptrIsTrue(clientCapabilities.LinkSupport)
}
15 changes: 8 additions & 7 deletions internal/ls/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
)

func (l *LanguageService) ProvideDiagnostics(ctx context.Context, uri lsproto.DocumentUri, clientOptions *lsproto.DiagnosticClientCapabilities) (lsproto.DocumentDiagnosticResponse, error) {
func (l *LanguageService) ProvideDiagnostics(ctx context.Context, uri lsproto.DocumentUri) (lsproto.DocumentDiagnosticResponse, error) {
program, file := l.getProgramAndFile(uri)

diagnostics := make([][]*ast.Diagnostic, 0, 4)
Expand All @@ -28,26 +28,27 @@ func (l *LanguageService) ProvideDiagnostics(ctx context.Context, uri lsproto.Do

return lsproto.RelatedFullDocumentDiagnosticReportOrUnchangedDocumentDiagnosticReport{
FullDocumentDiagnosticReport: &lsproto.RelatedFullDocumentDiagnosticReport{
Items: l.toLSPDiagnostics(clientOptions, diagnostics...),
Items: l.toLSPDiagnostics(ctx, diagnostics...),
},
}, nil
}

func (l *LanguageService) toLSPDiagnostics(clientOptions *lsproto.DiagnosticClientCapabilities, diagnostics ...[]*ast.Diagnostic) []*lsproto.Diagnostic {
func (l *LanguageService) toLSPDiagnostics(ctx context.Context, diagnostics ...[]*ast.Diagnostic) []*lsproto.Diagnostic {
size := 0
for _, diagSlice := range diagnostics {
size += len(diagSlice)
}
lspDiagnostics := make([]*lsproto.Diagnostic, 0, size)
for _, diagSlice := range diagnostics {
for _, diag := range diagSlice {
lspDiagnostics = append(lspDiagnostics, l.toLSPDiagnostic(clientOptions, diag))
lspDiagnostics = append(lspDiagnostics, l.toLSPDiagnostic(ctx, diag))
}
}
return lspDiagnostics
}

func (l *LanguageService) toLSPDiagnostic(clientOptions *lsproto.DiagnosticClientCapabilities, diagnostic *ast.Diagnostic) *lsproto.Diagnostic {
func (l *LanguageService) toLSPDiagnostic(ctx context.Context, diagnostic *ast.Diagnostic) *lsproto.Diagnostic {
clientOptions := lsproto.GetClientCapabilities(ctx).TextDocument.Diagnostic
var severity lsproto.DiagnosticSeverity
switch diagnostic.Category() {
case diagnostics.CategorySuggestion:
Expand All @@ -61,7 +62,7 @@ func (l *LanguageService) toLSPDiagnostic(clientOptions *lsproto.DiagnosticClien
}

var relatedInformation []*lsproto.DiagnosticRelatedInformation
if clientOptions != nil && ptrIsTrue(clientOptions.RelatedInformation) {
if clientOptions.RelatedInformation {
relatedInformation = make([]*lsproto.DiagnosticRelatedInformation, 0, len(diagnostic.RelatedInformation()))
for _, related := range diagnostic.RelatedInformation() {
relatedInformation = append(relatedInformation, &lsproto.DiagnosticRelatedInformation{
Expand All @@ -75,7 +76,7 @@ func (l *LanguageService) toLSPDiagnostic(clientOptions *lsproto.DiagnosticClien
}

var tags []lsproto.DiagnosticTag
if clientOptions != nil && clientOptions.TagSupport != nil && (diagnostic.ReportsUnnecessary() || diagnostic.ReportsDeprecated()) {
if len(clientOptions.TagSupport.ValueSet) > 0 && (diagnostic.ReportsUnnecessary() || diagnostic.ReportsDeprecated()) {
tags = make([]lsproto.DiagnosticTag, 0, 2)
if diagnostic.ReportsUnnecessary() && slices.Contains(clientOptions.TagSupport.ValueSet, lsproto.DiagnosticTagUnnecessary) {
tags = append(tags, lsproto.DiagnosticTagUnnecessary)
Expand Down
4 changes: 2 additions & 2 deletions internal/ls/findallreferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (l *LanguageService) ProvideReferences(ctx context.Context, params *lsproto
return lsproto.LocationsOrNull{Locations: &locations}, nil
}

func (l *LanguageService) ProvideImplementations(ctx context.Context, params *lsproto.ImplementationParams, clientSupportsLink bool) (lsproto.ImplementationResponse, error) {
func (l *LanguageService) ProvideImplementations(ctx context.Context, params *lsproto.ImplementationParams) (lsproto.ImplementationResponse, error) {
program, sourceFile := l.getProgramAndFile(params.TextDocument.Uri)
position := int(l.converters.LineAndCharacterToPosition(sourceFile, params.Position))
node := astnav.GetTouchingPropertyName(sourceFile, position)
Expand All @@ -452,7 +452,7 @@ func (l *LanguageService) ProvideImplementations(ctx context.Context, params *ls
}
}

if clientSupportsLink {
if lsproto.GetClientCapabilities(ctx).TextDocument.Implementation.LinkSupport {
links := l.convertEntriesToLocationLinks(entries)
return lsproto.LocationOrLocationsOrDefinitionLinksOrNull{DefinitionLinks: &links}, nil
}
Expand Down
5 changes: 4 additions & 1 deletion internal/ls/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ const (
typeFormatFlags = checker.TypeFormatFlagsUseAliasDefinedOutsideCurrentScope
)

func (l *LanguageService) ProvideHover(ctx context.Context, documentURI lsproto.DocumentUri, position lsproto.Position, contentFormat lsproto.MarkupKind) (lsproto.HoverResponse, error) {
func (l *LanguageService) ProvideHover(ctx context.Context, documentURI lsproto.DocumentUri, position lsproto.Position) (lsproto.HoverResponse, error) {
caps := lsproto.GetClientCapabilities(ctx)
contentFormat := lsproto.PreferredMarkupKind(caps.TextDocument.Hover.ContentFormat)

program, file := l.getProgramAndFile(documentURI)
node := astnav.GetTouchingPropertyName(file, int(l.converters.LineAndCharacterToPosition(file, position)))
if node.Kind == ast.KindSourceFile {
Expand Down
19 changes: 8 additions & 11 deletions internal/ls/signaturehelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,14 @@ func (l *LanguageService) ProvideSignatureHelp(
documentURI lsproto.DocumentUri,
position lsproto.Position,
context *lsproto.SignatureHelpContext,
clientOptions *lsproto.SignatureHelpClientCapabilities,
docFormat lsproto.MarkupKind,
) (lsproto.SignatureHelpResponse, error) {
program, sourceFile := l.getProgramAndFile(documentURI)
items := l.GetSignatureHelpItems(
ctx,
int(l.converters.LineAndCharacterToPosition(sourceFile, position)),
program,
sourceFile,
context,
clientOptions,
docFormat)
context)
return lsproto.SignatureHelpOrNull{SignatureHelp: items}, nil
}

Expand All @@ -64,8 +60,6 @@ func (l *LanguageService) GetSignatureHelpItems(
program *compiler.Program,
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 @@ -143,12 +137,12 @@ func (l *LanguageService) GetSignatureHelpItems(

// return typeChecker.runWithCancellationToken(cancellationToken, typeChecker =>
if candidateInfo.candidateInfo != nil {
return l.createSignatureHelpItems(candidateInfo.candidateInfo.candidates, candidateInfo.candidateInfo.resolvedSignature, argumentInfo, sourceFile, typeChecker, onlyUseSyntacticOwners, clientOptions, docFormat)
return l.createSignatureHelpItems(ctx, candidateInfo.candidateInfo.candidates, candidateInfo.candidateInfo.resolvedSignature, argumentInfo, sourceFile, typeChecker, onlyUseSyntacticOwners)
}
return createTypeHelpItems(candidateInfo.typeInfo, argumentInfo, sourceFile, clientOptions, typeChecker)
return createTypeHelpItems(candidateInfo.typeInfo, argumentInfo, sourceFile, typeChecker)
}

func createTypeHelpItems(symbol *ast.Symbol, argumentInfo *argumentListInfo, sourceFile *ast.SourceFile, clientOptions *lsproto.SignatureHelpClientCapabilities, c *checker.Checker) *lsproto.SignatureHelp {
func createTypeHelpItems(symbol *ast.Symbol, argumentInfo *argumentListInfo, sourceFile *ast.SourceFile, c *checker.Checker) *lsproto.SignatureHelp {
typeParameters := c.GetLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol)
if typeParameters == nil {
return nil
Expand Down Expand Up @@ -205,7 +199,10 @@ func getTypeHelpItem(symbol *ast.Symbol, typeParameter []*checker.Type, enclosin
}
}

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 {
func (l *LanguageService) createSignatureHelpItems(ctx context.Context, candidates []*checker.Signature, resolvedSignature *checker.Signature, argumentInfo *argumentListInfo, sourceFile *ast.SourceFile, c *checker.Checker, useFullPrefix bool) *lsproto.SignatureHelp {
caps := lsproto.GetClientCapabilities(ctx)
docFormat := lsproto.PreferredMarkupKind(caps.TextDocument.SignatureHelp.SignatureInformation.DocumentationFormat)

enclosingDeclaration := getEnclosingDeclarationFromInvocation(argumentInfo.invocation)
if enclosingDeclaration == nil {
return nil
Expand Down
18 changes: 7 additions & 11 deletions internal/ls/string_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func (l *LanguageService) getStringLiteralCompletions(
position int,
contextToken *ast.Node,
compilerOptions *core.CompilerOptions,
clientOptions *lsproto.CompletionClientCapabilities,
) *lsproto.CompletionList {
// !!! reference comment
if IsInString(file, position, contextToken) {
Expand All @@ -65,7 +64,6 @@ func (l *LanguageService) getStringLiteralCompletions(
file,
position,
compilerOptions,
clientOptions,
)
}
return nil
Expand All @@ -78,7 +76,6 @@ func (l *LanguageService) convertStringLiteralCompletions(
file *ast.SourceFile,
position int,
options *core.CompilerOptions,
clientOptions *lsproto.CompletionClientCapabilities,
) *lsproto.CompletionList {
if completion == nil {
return nil
Expand All @@ -88,7 +85,7 @@ func (l *LanguageService) convertStringLiteralCompletions(
switch {
case completion.fromPaths != nil:
completion := completion.fromPaths
return l.convertPathCompletions(completion, file, position, clientOptions)
return l.convertPathCompletions(ctx, completion, file, position)
case completion.fromProperties != nil:
completion := completion.fromProperties
data := &completionDataData{
Expand All @@ -105,11 +102,10 @@ func (l *LanguageService) convertStringLiteralCompletions(
position,
file,
options,
clientOptions,
)
defaultCommitCharacters := getDefaultCommitCharacters(completion.hasIndexSignature)
itemDefaults := l.setItemDefaults(
clientOptions,
ctx,
position,
file,
items,
Expand All @@ -134,6 +130,7 @@ func (l *LanguageService) convertStringLiteralCompletions(
items := core.Map(completion.types, func(t *checker.StringLiteralType) *lsproto.CompletionItem {
name := printer.EscapeString(t.AsLiteralType().Value().(string), quoteChar)
return l.createLSPCompletionItem(
ctx,
name,
"", /*insertText*/
"", /*filterText*/
Expand All @@ -145,7 +142,6 @@ func (l *LanguageService) convertStringLiteralCompletions(
nil, /*labelDetails*/
file,
position,
clientOptions,
false, /*isMemberCompletion*/
false, /*isSnippet*/
false, /*hasAction*/
Expand All @@ -156,7 +152,7 @@ func (l *LanguageService) convertStringLiteralCompletions(
})
defaultCommitCharacters := getDefaultCommitCharacters(completion.isNewIdentifier)
itemDefaults := l.setItemDefaults(
clientOptions,
ctx,
position,
file,
items,
Expand All @@ -174,16 +170,17 @@ func (l *LanguageService) convertStringLiteralCompletions(
}

func (l *LanguageService) convertPathCompletions(
ctx context.Context,
pathCompletions []*pathCompletion,
file *ast.SourceFile,
position int,
clientOptions *lsproto.CompletionClientCapabilities,
) *lsproto.CompletionList {
isNewIdentifierLocation := true // The user may type in a path that doesn't yet exist, creating a "new identifier" with respect to the collection of identifiers the server is aware of.
defaultCommitCharacters := getDefaultCommitCharacters(isNewIdentifierLocation)
items := core.Map(pathCompletions, func(pathCompletion *pathCompletion) *lsproto.CompletionItem {
replacementSpan := l.createLspRangeFromBounds(pathCompletion.textRange.Pos(), pathCompletion.textRange.End(), file)
return l.createLSPCompletionItem(
ctx,
pathCompletion.name,
"", /*insertText*/
"", /*filterText*/
Expand All @@ -195,7 +192,6 @@ func (l *LanguageService) convertPathCompletions(
nil, /*labelDetails*/
file,
position,
clientOptions,
false, /*isMemberCompletion*/
false, /*isSnippet*/
false, /*hasAction*/
Expand All @@ -205,7 +201,7 @@ func (l *LanguageService) convertPathCompletions(
)
})
itemDefaults := l.setItemDefaults(
clientOptions,
ctx,
position,
file,
items,
Expand Down
4 changes: 2 additions & 2 deletions internal/ls/symbols.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"github.com/microsoft/typescript-go/internal/stringutil"
)

func (l *LanguageService) ProvideDocumentSymbols(ctx context.Context, documentURI lsproto.DocumentUri, hierarchicalSupport bool) (lsproto.DocumentSymbolResponse, error) {
func (l *LanguageService) ProvideDocumentSymbols(ctx context.Context, documentURI lsproto.DocumentUri) (lsproto.DocumentSymbolResponse, error) {
_, file := l.getProgramAndFile(documentURI)
if hierarchicalSupport {
if lsproto.GetClientCapabilities(ctx).TextDocument.DocumentSymbol.HierarchicalDocumentSymbolSupport {
symbols := l.getDocumentSymbolsForChildren(ctx, file.AsNode())
return lsproto.SymbolInformationsOrDocumentSymbolsOrNull{DocumentSymbols: &symbols}, nil
}
Expand Down
Loading