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
4 changes: 2 additions & 2 deletions internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,8 +1207,8 @@ func (b *nodeBuilderImpl) getSpecifierForModuleSymbol(symbol *ast.Symbol, overri
contextFile,
host,
modulespecifiers.UserPreferences{
ImportModuleSpecifierPreference: specifierPref,
ImportModuleSpecifierEndingPreference: endingPref,
ImportModuleSpecifierPreference: specifierPref,
ImportModuleSpecifierEnding: endingPref,
},
modulespecifiers.ModuleSpecifierOptions{
OverrideImportMode: overrideImportMode,
Expand Down
8 changes: 4 additions & 4 deletions internal/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -1611,11 +1611,11 @@ func (f *FourslashTest) verifyBaselineRename(

var renameOptions strings.Builder
if preferences != nil {
if preferences.UseAliasesForRename != nil {
fmt.Fprintf(&renameOptions, "// @useAliasesForRename: %v\n", *preferences.UseAliasesForRename)
if preferences.UseAliasesForRename != core.TSUnknown {
fmt.Fprintf(&renameOptions, "// @useAliasesForRename: %v\n", preferences.UseAliasesForRename.IsTrue())
}
if preferences.QuotePreference != nil {
fmt.Fprintf(&renameOptions, "// @quotePreference: %v\n", *preferences.QuotePreference)
if preferences.QuotePreference != ls.QuotePreferenceUnknown {
fmt.Fprintf(&renameOptions, "// @quotePreference: %v\n", preferences.QuotePreference)
}
}

Expand Down
13 changes: 7 additions & 6 deletions internal/fourslash/tests/autoImportCompletion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fourslash_test
import (
"testing"

"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/fourslash"
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
"github.com/microsoft/typescript-go/internal/ls"
Expand All @@ -26,8 +27,8 @@ a/**/
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
UserPreferences: &ls.UserPreferences{
IncludeCompletionsForModuleExports: PtrTo(true),
IncludeCompletionsForImportStatements: PtrTo(true),
IncludeCompletionsForModuleExports: core.TSTrue,
IncludeCompletionsForImportStatements: core.TSTrue,
},
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
Expand Down Expand Up @@ -56,8 +57,8 @@ a/**/
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
UserPreferences: &ls.UserPreferences{
IncludeCompletionsForModuleExports: PtrTo(true),
IncludeCompletionsForImportStatements: PtrTo(true),
IncludeCompletionsForModuleExports: core.TSTrue,
IncludeCompletionsForImportStatements: core.TSTrue,
},
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
Expand Down Expand Up @@ -87,8 +88,8 @@ b/**/
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
UserPreferences: &ls.UserPreferences{
IncludeCompletionsForModuleExports: PtrTo(true),
IncludeCompletionsForImportStatements: PtrTo(true),
IncludeCompletionsForModuleExports: core.TSTrue,
IncludeCompletionsForImportStatements: core.TSTrue,
},
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
Expand Down
4 changes: 2 additions & 2 deletions internal/fourslash/tests/gen/renameExportSpecifier2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import (
"testing"

"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/fourslash"
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
"github.com/microsoft/typescript-go/internal/ls"
"github.com/microsoft/typescript-go/internal/testutil"
)
Expand All @@ -20,5 +20,5 @@
import { name } from './a';
const x = name.toString();`
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyBaselineRename(t, &ls.UserPreferences{UseAliasesForRename: PtrTo(false)}, "")
f.VerifyBaselineRename(t, &ls.UserPreferences{UseAliasesForRename: core.TSFalse}, "")

Check failure on line 23 in internal/fourslash/tests/gen/renameExportSpecifier2_test.go

View workflow job for this annotation

GitHub Actions / generate

cannot use PtrTo(false) (value of type *bool) as core.Tristate value in struct literal
}
4 changes: 2 additions & 2 deletions internal/fourslash/tests/gen/renameExportSpecifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import (
"testing"

"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/fourslash"
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
"github.com/microsoft/typescript-go/internal/ls"
"github.com/microsoft/typescript-go/internal/testutil"
)
Expand All @@ -20,5 +20,5 @@
import { name } from './a';
const x = name.toString();`
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyBaselineRename(t, &ls.UserPreferences{UseAliasesForRename: PtrTo(false)}, "")
f.VerifyBaselineRename(t, &ls.UserPreferences{UseAliasesForRename: core.TSFalse}, "")

Check failure on line 23 in internal/fourslash/tests/gen/renameExportSpecifier_test.go

View workflow job for this annotation

GitHub Actions / generate

cannot use PtrTo(false) (value of type *bool) as core.Tristate value in struct literal
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import (
"testing"

"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/fourslash"
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
"github.com/microsoft/typescript-go/internal/ls"
"github.com/microsoft/typescript-go/internal/testutil"
)
Expand All @@ -16,5 +16,5 @@
const content = `[|class [|{| "contextRangeIndex": 0 |}A|] {}|]
module.exports = { [|A|] }`
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyBaselineRename(t, &ls.UserPreferences{UseAliasesForRename: PtrTo(true)}, f.Ranges()[1], f.Ranges()[2])
f.VerifyBaselineRename(t, &ls.UserPreferences{UseAliasesForRename: core.TSTrue}, f.Ranges()[1], f.Ranges()[2])

Check failure on line 19 in internal/fourslash/tests/gen/renameModuleExportsProperties1_test.go

View workflow job for this annotation

GitHub Actions / generate

cannot use PtrTo(true) (value of type *bool) as core.Tristate value in struct literal
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import (
"testing"

"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/fourslash"
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
"github.com/microsoft/typescript-go/internal/ls"
"github.com/microsoft/typescript-go/internal/testutil"
)
Expand All @@ -18,5 +18,5 @@
[|class [|{| "contextRangeIndex": 0 |}A|] {}|]
module.exports = { [|A|] }`
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyBaselineRename(t, &ls.UserPreferences{UseAliasesForRename: PtrTo(true)}, f.Ranges()[1], f.Ranges()[2])
f.VerifyBaselineRename(t, &ls.UserPreferences{UseAliasesForRename: core.TSTrue}, f.Ranges()[1], f.Ranges()[2])

Check failure on line 21 in internal/fourslash/tests/gen/renameModuleExportsProperties3_test.go

View workflow job for this annotation

GitHub Actions / generate

cannot use PtrTo(true) (value of type *bool) as core.Tristate value in struct literal
}
4 changes: 2 additions & 2 deletions internal/fourslash/tests/gen/renameNamedImport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import (
"testing"

"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/fourslash"
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
"github.com/microsoft/typescript-go/internal/ls"
"github.com/microsoft/typescript-go/internal/testutil"
)
Expand All @@ -28,5 +28,5 @@
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.GoToFile(t, "/home/src/workspaces/project/lib/index.ts")
f.GoToFile(t, "/home/src/workspaces/project/src/index.ts")
f.VerifyBaselineRename(t, &ls.UserPreferences{UseAliasesForRename: PtrTo(true)}, "i")
f.VerifyBaselineRename(t, &ls.UserPreferences{UseAliasesForRename: core.TSTrue}, "i")

Check failure on line 31 in internal/fourslash/tests/gen/renameNamedImport_test.go

View workflow job for this annotation

GitHub Actions / generate

cannot use PtrTo(true) (value of type *bool) as core.Tristate value in struct literal
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"testing"

"github.com/microsoft/typescript-go/internal/fourslash"
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
"github.com/microsoft/typescript-go/internal/ls"
"github.com/microsoft/typescript-go/internal/testutil"
)
Expand All @@ -16,5 +15,5 @@
const content = `const foo = { [|0|]: true };
foo[[|0|]];`
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyBaselineRenameAtRangesWithText(t, &ls.UserPreferences{QuotePreference: PtrTo(ls.QuotePreference("single"))}, "0")
f.VerifyBaselineRenameAtRangesWithText(t, &ls.UserPreferences{QuotePreference: ls.QuotePreference("single")}, "0")
}

Check failure on line 19 in internal/fourslash/tests/gen/renameNumericalIndexSingleQuoted_test.go

View workflow job for this annotation

GitHub Actions / generate

cannot use PtrTo(ls.QuotePreference("single")) (value of type *ls.QuotePreference) as ls.QuotePreference value in struct literal
4 changes: 2 additions & 2 deletions internal/fourslash/tests/gen/renameRestBindingElement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import (
"testing"

"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/fourslash"
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
"github.com/microsoft/typescript-go/internal/ls"
"github.com/microsoft/typescript-go/internal/testutil"
)
Expand All @@ -22,5 +22,5 @@
[|rest|];
}`
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyBaselineRename(t, &ls.UserPreferences{UseAliasesForRename: PtrTo(true)}, f.Ranges()[1])
f.VerifyBaselineRename(t, &ls.UserPreferences{UseAliasesForRename: core.TSTrue}, f.Ranges()[1])

Check failure on line 25 in internal/fourslash/tests/gen/renameRestBindingElement_test.go

View workflow job for this annotation

GitHub Actions / generate

cannot use PtrTo(true) (value of type *bool) as core.Tristate value in struct literal
}
4 changes: 2 additions & 2 deletions internal/ls/autoimportfixes.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (ct *changeTracker) getNewImports(
// even though it's not an error, it would add unnecessary runtime emit.
topLevelTypeOnly := (defaultImport == nil || needsTypeOnly(defaultImport.addAsTypeOnly)) &&
core.Every(namedImports, func(i *Import) bool { return needsTypeOnly(i.addAsTypeOnly) }) ||
(compilerOptions.VerbatimModuleSyntax.IsTrue() || ptrIsTrue(preferences.PreferTypeOnlyAutoImports)) &&
(compilerOptions.VerbatimModuleSyntax.IsTrue() || preferences.PreferTypeOnlyAutoImports) &&
defaultImport != nil && defaultImport.addAsTypeOnly != AddAsTypeOnlyNotAllowed && !core.Some(namedImports, func(i *Import) bool { return i.addAsTypeOnly == AddAsTypeOnlyNotAllowed })

var defaultImportNode *ast.Node
Expand Down Expand Up @@ -321,5 +321,5 @@ func needsTypeOnly(addAsTypeOnly AddAsTypeOnly) bool {
}

func shouldUseTypeOnly(addAsTypeOnly AddAsTypeOnly, preferences *UserPreferences) bool {
return needsTypeOnly(addAsTypeOnly) || addAsTypeOnly != AddAsTypeOnlyNotAllowed && preferences.PreferTypeOnlyAutoImports != nil && *preferences.PreferTypeOnlyAutoImports
return needsTypeOnly(addAsTypeOnly) || addAsTypeOnly != AddAsTypeOnlyNotAllowed && preferences.PreferTypeOnlyAutoImports
}
29 changes: 11 additions & 18 deletions internal/ls/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (l *LanguageService) getCompletionsAtPosition(

if triggerCharacter != nil && *triggerCharacter == " " {
// `isValidTrigger` ensures we are at `import |`
if ptrIsTrue(preferences.IncludeCompletionsForImportStatements) {
if preferences.IncludeCompletionsForImportStatements.IsTrue() {
return &lsproto.CompletionList{
IsIncomplete: true,
}
Expand Down Expand Up @@ -586,7 +586,7 @@ func (l *LanguageService) getCompletionData(
}
keywordFilters = keywordFiltersFromSyntaxKind(importStatementCompletionInfo.keywordCompletion)
}
if importStatementCompletionInfo.replacementSpan != nil && ptrIsTrue(preferences.IncludeCompletionsForImportStatements) {
if importStatementCompletionInfo.replacementSpan != nil && preferences.IncludeCompletionsForImportStatements.IsTrue() {
// !!! flags |= CompletionInfoFlags.IsImportStatementCompletion;
importStatementCompletion = &importStatementCompletionInfo
isNewIdentifierLocation = importStatementCompletionInfo.isNewIdentifierLocation
Expand Down Expand Up @@ -936,7 +936,7 @@ func (l *LanguageService) getCompletionData(
insertQuestionDot := false
if typeChecker.IsNullableType(t) {
canCorrectToQuestionDot := isRightOfDot && !isRightOfQuestionDot &&
!ptrIsFalse(preferences.IncludeAutomaticOptionalChainCompletions)
!preferences.IncludeAutomaticOptionalChainCompletions.IsFalse()
if canCorrectToQuestionDot || isRightOfQuestionDot {
t = typeChecker.GetNonNullableType(t)
if canCorrectToQuestionDot {
Expand All @@ -963,7 +963,7 @@ func (l *LanguageService) getCompletionData(
insertQuestionDot := false
if typeChecker.IsNullableType(t) {
canCorrectToQuestionDot := isRightOfDot && !isRightOfQuestionDot &&
!ptrIsFalse(preferences.IncludeAutomaticOptionalChainCompletions)
!preferences.IncludeAutomaticOptionalChainCompletions.IsFalse()

if canCorrectToQuestionDot || isRightOfQuestionDot {
t = typeChecker.GetNonNullableType(t)
Expand Down Expand Up @@ -1128,7 +1128,7 @@ func (l *LanguageService) getCompletionData(
symbols = append(symbols, filteredMembers...)

// Set sort texts.
transformObjectLiteralMembers := ptrIsTrue(preferences.IncludeCompletionsWithObjectLiteralMethodSnippets) &&
transformObjectLiteralMembers := preferences.IncludeCompletionsWithObjectLiteralMethodSnippets.IsTrue() &&
objectLikeContainer.Kind == ast.KindObjectLiteralExpression
for _, member := range filteredMembers {
symbolId := ast.GetSymbolId(member)
Expand Down Expand Up @@ -1156,7 +1156,7 @@ func (l *LanguageService) getCompletionData(
return true
}
// If not already a module, must have modules enabled.
if !ptrIsTrue(preferences.IncludeCompletionsForModuleExports) {
if !preferences.IncludeCompletionsForModuleExports.IsTrue() {
return false
}
// Always using ES modules in 6.0+
Expand Down Expand Up @@ -2240,7 +2240,7 @@ func (l *LanguageService) createCompletionItem(
}
}

if ptrIsTrue(preferences.IncludeCompletionsWithClassMemberSnippets) &&
if preferences.IncludeCompletionsWithClassMemberSnippets.IsTrue() &&
data.completionKind == CompletionKindMemberLike &&
isClassLikeMemberCompletion(symbol, data.location, file) {
// !!! class member completions
Expand All @@ -2261,13 +2261,13 @@ func (l *LanguageService) createCompletionItem(
if data.isJsxIdentifierExpected &&
!data.isRightOfOpenTag &&
clientSupportsItemSnippet(clientOptions) &&
!jsxAttributeCompletionStyleIs(preferences.JsxAttributeCompletionStyle, JsxAttributeCompletionStyleNone) &&
preferences.JsxAttributeCompletionStyle != JsxAttributeCompletionStyleNone &&
!(ast.IsJsxAttribute(data.location.Parent) && data.location.Parent.Initializer() != nil) {
useBraces := jsxAttributeCompletionStyleIs(preferences.JsxAttributeCompletionStyle, JsxAttributeCompletionStyleBraces)
useBraces := preferences.JsxAttributeCompletionStyle == JsxAttributeCompletionStyleBraces
t := typeChecker.GetTypeOfSymbolAtLocation(symbol, data.location)

// If is boolean like or undefined, don't return a snippet, we want to return just the completion.
if jsxAttributeCompletionStyleIs(preferences.JsxAttributeCompletionStyle, JsxAttributeCompletionStyleAuto) &&
if preferences.JsxAttributeCompletionStyle == JsxAttributeCompletionStyleAuto &&
!t.IsBooleanLike() &&
!(t.IsUnion() && core.Some(t.Types(), (*checker.Type).IsBooleanLike)) {
if t.IsStringLike() ||
Expand Down Expand Up @@ -2533,13 +2533,6 @@ func boolToPtr(v bool) *bool {
return nil
}

func jsxAttributeCompletionStyleIs(preferenceStyle *JsxAttributeCompletionStyle, style JsxAttributeCompletionStyle) bool {
if preferenceStyle == nil {
return false
}
return *preferenceStyle == style
}

func getLineOfPosition(file *ast.SourceFile, pos int) int {
line, _ := scanner.GetECMALineAndCharacterOfPosition(file, pos)
return line
Expand Down Expand Up @@ -5170,7 +5163,7 @@ func (l *LanguageService) getSymbolCompletionFromItemData(
}
}

completionData := l.getCompletionData(ctx, ch, file, position, &UserPreferences{IncludeCompletionsForModuleExports: ptrTo(true), IncludeCompletionsForImportStatements: ptrTo(true)})
completionData := l.getCompletionData(ctx, ch, file, position, &UserPreferences{IncludeCompletionsForModuleExports: core.TSTrue, IncludeCompletionsForImportStatements: core.TSTrue})
if completionData == nil {
return detailsData{}
}
Expand Down
67 changes: 0 additions & 67 deletions internal/ls/types.go

This file was deleted.

Loading
Loading