Skip to content

Fixed some completions close to end of files #1356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2025
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
60 changes: 25 additions & 35 deletions internal/fourslash/_scripts/failingTests.txt
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry for the noisy diff here - I sorted this list to help with diffing when comparing this list against the list of all current failing test cases. Upon reques, I can revert that change and just remove the newly passing tests surgically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my process was a little bit manual when it comes to this, maybe there is a better one to learn what can be unskipped? cc @gabritto

Copy link
Member

Choose a reason for hiding this comment

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

I usually just run a command in the terminal to sort/deduplicate this as part of updating. What I really need to do is to add a script or something to update the failing tests list. I'll do that soon, but meanwhile you can do whatever is easiest.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
TestAutoImportsWithRootDirsAndRootedPath01
TestClosedCommentsInConstructor
TestCodeCompletionEscaping
TestCompletionAfterNewline
TestCompletionAfterNewline2
TestCompletionCloneQuestionToken
TestCompletionEntryForArgumentConstrainedToString
TestCompletionEntryForArrayElementConstrainedToString
Expand All @@ -11,6 +9,13 @@ TestCompletionEntryForClassMembers_StaticWhenBaseTypeIsNotResolved
TestCompletionExportFrom
TestCompletionForComputedStringProperties
TestCompletionForStringLiteral
TestCompletionForStringLiteral_quotePreference
TestCompletionForStringLiteral_quotePreference1
TestCompletionForStringLiteral_quotePreference2
TestCompletionForStringLiteral_quotePreference3
TestCompletionForStringLiteral_quotePreference4
TestCompletionForStringLiteral_quotePreference5
TestCompletionForStringLiteral_quotePreference6
TestCompletionForStringLiteral12
TestCompletionForStringLiteral15
TestCompletionForStringLiteral2
Expand All @@ -37,13 +42,6 @@ TestCompletionForStringLiteralRelativeImport4
TestCompletionForStringLiteralRelativeImport6
TestCompletionForStringLiteralRelativeImportAllowJSTrue
TestCompletionForStringLiteralWithDynamicImport
TestCompletionForStringLiteral_quotePreference
TestCompletionForStringLiteral_quotePreference1
TestCompletionForStringLiteral_quotePreference2
TestCompletionForStringLiteral_quotePreference3
TestCompletionForStringLiteral_quotePreference4
TestCompletionForStringLiteral_quotePreference5
TestCompletionForStringLiteral_quotePreference6
TestCompletionImportMeta
TestCompletionImportMetaWithGlobalDeclaration
TestCompletionImportModuleSpecifierEndingDts
Expand All @@ -53,9 +51,9 @@ TestCompletionImportModuleSpecifierEndingTs
TestCompletionImportModuleSpecifierEndingTsxPreserve
TestCompletionImportModuleSpecifierEndingTsxReact
TestCompletionImportModuleSpecifierEndingUnsupportedExtension
TestCompletionInfoWithExplicitTypeArguments
TestCompletionInFunctionLikeBody_includesPrimitiveTypes
TestCompletionInJsDoc
TestCompletionInfoWithExplicitTypeArguments
TestCompletionListAndMemberListOnCommentedDot
TestCompletionListAndMemberListOnCommentedLine
TestCompletionListAndMemberListOnCommentedWhiteSpace
Expand All @@ -66,7 +64,6 @@ TestCompletionListClassMembers
TestCompletionListForExportEquals
TestCompletionListForTransitivelyExportedMembers01
TestCompletionListForTransitivelyExportedMembers04
TestCompletionListForUnicodeEscapeName
TestCompletionListFunctionExpression
TestCompletionListFunctionMembers
TestCompletionListInArrowFunctionInUnclosedCallSite01
Expand All @@ -76,7 +73,6 @@ TestCompletionListInComments
TestCompletionListInComments2
TestCompletionListInComments3
TestCompletionListInExtendsClause
TestCompletionListInFunctionDeclaration
TestCompletionListInImportClause01
TestCompletionListInImportClause05
TestCompletionListInImportClause06
Expand All @@ -86,54 +82,48 @@ TestCompletionListInUnclosedCommaExpression01
TestCompletionListInUnclosedCommaExpression02
TestCompletionListInUnclosedFunction08
TestCompletionListInUnclosedFunction09
TestCompletionListInUnclosedFunction10
TestCompletionListInUnclosedFunction11
TestCompletionListInUnclosedTaggedTemplate01
TestCompletionListInUnclosedTaggedTemplate02
TestCompletionListInUnclosedTemplate01
TestCompletionListInUnclosedTemplate02
TestCompletionListInvalidMemberNames2
TestCompletionListInvalidMemberNames_withExistingIdentifier
TestCompletionListInvalidMemberNames2
TestCompletionListOnAliases2
TestCompletionListPrivateNames
TestCompletionListPrivateNamesAccessors
TestCompletionListPrivateNamesMethods
TestCompletionListsStringLiteralTypeAsIndexedAccessTypeObject
TestCompletionListStaticMembers
TestCompletionListStaticProtectedMembers
TestCompletionListStaticProtectedMembers2
TestCompletionListStaticProtectedMembers3
TestCompletionListStringParenthesizedExpression
TestCompletionListStringParenthesizedType
TestCompletionListWithoutVariableinitializer
TestCompletionListsStringLiteralTypeAsIndexedAccessTypeObject
TestCompletionNoAutoInsertQuestionDotWithUserPreferencesOff
TestCompletionOfAwaitPromise6
TestCompletionPreferredSuggestions1
TestCompletionWithConditionalOperatorMissingColon
TestCompletionsAfterJSDoc
TestCompletionsBeforeRestArg1
TestCompletionsECMAPrivateMemberTriggerCharacter
TestCompletionsImportDefaultExportCrash1
TestCompletionsImport_computedSymbolName
TestCompletionsImport_umdDefaultNoCrash2
TestCompletionsInRequire
TestCompletionsInterfaceElement
TestCompletionsJSDocImportTagAttributesEmptyModuleSpecifier1
TestCompletionsJSDocImportTagAttributesErrorModuleSpecifier1
TestCompletionsJSDocImportTagEmptyModuleSpecifier1
TestCompletionsJSDocNoCrash1
TestCompletionsJSDocNoCrash2
TestCompletionsJsPropertyAssignment
TestCompletionsJsdocParamTypeBeforeName
TestCompletionsJsdocTypeTagCast
TestCompletionsJsPropertyAssignment
TestCompletionsJsxAttribute2
TestCompletionsKeyof
TestCompletionsLiteralFromInferenceWithinInferredType3
TestCompletionsMergedDeclarations1
TestCompletionsNamespaceMergedWithClass
TestCompletionsNamespaceName
TestCompletionsNewTarget
TestCompletionsNonExistentImport
TestCompletionsOptionalKindModifier
TestCompletionsOptionalMethod
TestCompletionsOverridingMethod1
Expand All @@ -144,13 +134,13 @@ TestCompletionsOverridingMethod4
TestCompletionsOverridingMethod9
TestCompletionsOverridingMethodCrash1
TestCompletionsOverridingProperties1
TestCompletionsPathsJsonModule
TestCompletionsPathsRelativeJsonModule
TestCompletionsPaths_importType
TestCompletionsPaths_kinds
TestCompletionsPaths_pathMapping
TestCompletionsPaths_pathMapping_nonTrailingWildcard1
TestCompletionsPaths_pathMapping_parentDirectory
TestCompletionsPathsJsonModule
TestCompletionsPathsRelativeJsonModule
TestCompletionsPropertiesPriorities
TestCompletionsRecommended_union
TestCompletionsRedeclareModuleAsGlobal
Expand All @@ -160,6 +150,7 @@ TestCompletionsSymbolMembers
TestCompletionsTriggerCharacter
TestCompletionsUniqueSymbol1
TestCompletionsWithStringReplacementMode1
TestCompletionWithConditionalOperatorMissingColon
TestExportEqualCallableInterface
TestGetJavaScriptCompletions1
TestGetJavaScriptCompletions10
Expand All @@ -181,42 +172,42 @@ TestGetJavaScriptCompletions8
TestGetJavaScriptCompletions9
TestGetJavaScriptGlobalCompletions1
TestGetJavaScriptQuickInfo8
TestImportCompletions_importsMap1
TestImportCompletions_importsMap2
TestImportCompletions_importsMap3
TestImportCompletions_importsMap4
TestImportCompletions_importsMap5
TestImportCompletionsPackageJsonExportsSpecifierEndsInTs
TestImportCompletionsPackageJsonExportsTrailingSlash1
TestImportCompletionsPackageJsonImports_ts
TestImportCompletionsPackageJsonImportsConditions1
TestImportCompletionsPackageJsonImportsLength1
TestImportCompletionsPackageJsonImportsLength2
TestImportCompletionsPackageJsonImportsPattern
TestImportCompletionsPackageJsonImportsPattern2
TestImportCompletionsPackageJsonImportsPattern_capsInPath1
TestImportCompletionsPackageJsonImportsPattern_capsInPath2
TestImportCompletionsPackageJsonImportsPattern_js_ts
TestImportCompletionsPackageJsonImportsPattern_ts
TestImportCompletionsPackageJsonImportsPattern_ts_ts
TestImportCompletionsPackageJsonImports_ts
TestImportCompletions_importsMap1
TestImportCompletions_importsMap2
TestImportCompletions_importsMap3
TestImportCompletions_importsMap4
TestImportCompletions_importsMap5
TestImportStatementCompletions4
TestImportCompletionsPackageJsonImportsPattern2
TestImportStatementCompletions_noPatternAmbient
TestImportStatementCompletions_pnpmTransitive
TestImportStatementCompletions4
TestImportTypeMemberCompletions
TestJavaScriptModules12
TestJavaScriptModules14
TestJavascriptModules20
TestJavascriptModules21
TestJavascriptModulesTypeImport
TestJsdocExtendsTagCompletion
TestJsDocFunctionSignatures3
TestJsDocGenerics1
TestJsdocExtendsTagCompletion
TestJsdocImplementsTagCompletion
TestJsdocOverloadTagCompletion
TestJsdocParamTagSpecialKeywords
TestJsdocParameterNameCompletion
TestJsdocPropTagCompletion
TestJsdocParamTagSpecialKeywords
TestJsdocPropertyTagCompletion
TestJsdocPropTagCompletion
TestJsdocSatisfiesTagCompletion1
TestJsdocTemplatePrototypeCompletions
TestJsdocTemplateTagCompletion
Expand Down Expand Up @@ -279,7 +270,6 @@ TestPathCompletionsTypesVersionsWildcard3
TestPathCompletionsTypesVersionsWildcard4
TestPathCompletionsTypesVersionsWildcard5
TestPathCompletionsTypesVersionsWildcard6
TestSatisfiesOperatorCompletion
TestStringCompletionsImportOrExportSpecifier
TestStringCompletionsVsEscaping
TestStringLiteralTypeCompletionsInTypeArgForNonGeneric1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCompletionAfterNewline2(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `let foo = 5 as const /*1*/
/*2*/`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCompletionAfterNewline(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `let foo /*1*/
/*2*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestCompletionListForUnicodeEscapeName(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `function \u0042 () { /*0*/ }
export default function \u0043 () {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestCompletionListInFunctionDeclaration(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `var a = 0;
function foo(/**/`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestCompletionListInUnclosedFunction10(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `interface MyType {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestCompletionListInUnclosedFunction11(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `interface MyType {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCompletionsImportDefaultExportCrash1(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @module: node18
// @allowJs: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCompletionsImport_umdDefaultNoCrash2(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @moduleResolution: node
// @allowJs: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestCompletionsNonExistentImport(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `import { NonExistentType } from "non-existent-module";
let foo: /**/`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestSatisfiesOperatorCompletion(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `type T = number;
var x;
Expand Down
20 changes: 18 additions & 2 deletions internal/ls/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,22 @@ func getLineOfPosition(file *ast.SourceFile, pos int) int {
return line
}

func getLineEndOfPosition(file *ast.SourceFile, pos int) int {
line := getLineOfPosition(file, pos)
lineStarts := scanner.GetLineStarts(file)
var lastCharPos int
if line+1 >= len(lineStarts) {
lastCharPos = file.End()
} else {
lastCharPos = int(lineStarts[line+1]) - 1
}
fullText := file.Text()
if lastCharPos > 0 && lastCharPos < len(fullText) && fullText[lastCharPos] == '\n' && fullText[lastCharPos-1] == '\r' {
return lastCharPos - 1
}
return lastCharPos
}

func isClassLikeMemberCompletion(symbol *ast.Symbol, location *ast.Node, file *ast.SourceFile) bool {
// !!! class member completions
return false
Expand Down Expand Up @@ -2723,7 +2739,7 @@ func getClosestSymbolDeclaration(contextToken *ast.Node, location *ast.Node) *as
})

if closestDeclaration == nil {
closestDeclaration = ast.FindAncestorOrQuit(contextToken, func(node *ast.Node) ast.FindAncestorResult {
closestDeclaration = ast.FindAncestorOrQuit(location, func(node *ast.Node) ast.FindAncestorResult {
if ast.IsFunctionBlock(node) || isArrowFunctionBody(node) || ast.IsBindingPattern(node) {
return ast.FindAncestorQuit
}
Expand Down Expand Up @@ -4338,7 +4354,7 @@ func isSolelyIdentifierDefinitionLocation(
return false
}
ancestorVariableDeclaration := ast.FindAncestor(parent, ast.IsVariableDeclaration)
if ancestorVariableDeclaration != nil && getLineOfPosition(file, contextToken.End()) < position {
if ancestorVariableDeclaration != nil && getLineEndOfPosition(file, contextToken.End()) < position {
// let a
// |
return false
Expand Down