diff --git a/internal/checker/nodebuilderimpl.go b/internal/checker/nodebuilderimpl.go index 9f07545c05..f189a3aafa 100644 --- a/internal/checker/nodebuilderimpl.go +++ b/internal/checker/nodebuilderimpl.go @@ -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, diff --git a/internal/fourslash/_scripts/convertFourslash.mts b/internal/fourslash/_scripts/convertFourslash.mts index 919d72b777..64c4c70632 100644 --- a/internal/fourslash/_scripts/convertFourslash.mts +++ b/internal/fourslash/_scripts/convertFourslash.mts @@ -911,6 +911,17 @@ function parseBaselineRenameArgs(funcName: string, args: readonly ts.Expression[ }]; } +function stringToTristate(s: string): string { + switch (s) { + case "true": + return "core.TSTrue"; + case "false": + return "core.TSFalse"; + default: + return "core.TSUnknown"; + } +} + function parseUserPreferences(arg: ts.ObjectLiteralExpression): string | undefined { const preferences: string[] = []; for (const prop of arg.properties) { @@ -918,10 +929,10 @@ function parseUserPreferences(arg: ts.ObjectLiteralExpression): string | undefin switch (prop.name.getText()) { // !!! other preferences case "providePrefixAndSuffixTextForRename": - preferences.push(`UseAliasesForRename: PtrTo(${prop.initializer.getText()})`); + preferences.push(`UseAliasesForRename: ${stringToTristate(prop.initializer.getText())}`); break; case "quotePreference": - preferences.push(`QuotePreference: PtrTo(ls.QuotePreference(${prop.initializer.getText()}))`); + preferences.push(`QuotePreference: ls.QuotePreference(${prop.initializer.getText()})`); break; } } @@ -1465,13 +1476,16 @@ function generateGoTest(failingTests: Set, test: GoTest): string { const commands = test.commands.map(cmd => generateCmd(cmd)).join("\n"); const imports = [`"github.com/microsoft/typescript-go/internal/fourslash"`]; // Only include these imports if the commands use them to avoid unused import errors. + if (commands.includes("core.")) { + imports.unshift(`"github.com/microsoft/typescript-go/internal/core"`); + } if (commands.includes("ls.")) { imports.push(`"github.com/microsoft/typescript-go/internal/ls"`); } if (commands.includes("lsproto.")) { imports.push(`"github.com/microsoft/typescript-go/internal/lsp/lsproto"`); } - if (usesHelper(commands)) { + if (usesFourslashUtil(commands)) { imports.push(`. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"`); } imports.push(`"github.com/microsoft/typescript-go/internal/testutil"`); @@ -1494,7 +1508,7 @@ func Test${testName}(t *testing.T) { return template; } -function usesHelper(goTxt: string): boolean { +function usesFourslashUtil(goTxt: string): boolean { for (const [_, constant] of completionConstants) { if (goTxt.includes(constant)) { return true; diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index 6b9e932aad..a488f7d2c5 100644 --- a/internal/fourslash/fourslash.go +++ b/internal/fourslash/fourslash.go @@ -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) } } diff --git a/internal/fourslash/tests/autoImportCompletion_test.go b/internal/fourslash/tests/autoImportCompletion_test.go index 53e473f0fe..7c5aeaf356 100644 --- a/internal/fourslash/tests/autoImportCompletion_test.go +++ b/internal/fourslash/tests/autoImportCompletion_test.go @@ -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" @@ -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{ @@ -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{ @@ -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{ diff --git a/internal/fourslash/tests/gen/renameExportSpecifier2_test.go b/internal/fourslash/tests/gen/renameExportSpecifier2_test.go index f0cadff970..404830405a 100644 --- a/internal/fourslash/tests/gen/renameExportSpecifier2_test.go +++ b/internal/fourslash/tests/gen/renameExportSpecifier2_test.go @@ -3,8 +3,8 @@ 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" "github.com/microsoft/typescript-go/internal/testutil" ) @@ -20,5 +20,5 @@ export { name/**/ }; 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}, "") } diff --git a/internal/fourslash/tests/gen/renameExportSpecifier_test.go b/internal/fourslash/tests/gen/renameExportSpecifier_test.go index 590d875928..0b4207e579 100644 --- a/internal/fourslash/tests/gen/renameExportSpecifier_test.go +++ b/internal/fourslash/tests/gen/renameExportSpecifier_test.go @@ -3,8 +3,8 @@ 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" "github.com/microsoft/typescript-go/internal/testutil" ) @@ -20,5 +20,5 @@ export { name as name/**/ }; 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}, "") } diff --git a/internal/fourslash/tests/gen/renameModuleExportsProperties1_test.go b/internal/fourslash/tests/gen/renameModuleExportsProperties1_test.go index 657685a1d9..012d2fc57c 100644 --- a/internal/fourslash/tests/gen/renameModuleExportsProperties1_test.go +++ b/internal/fourslash/tests/gen/renameModuleExportsProperties1_test.go @@ -3,8 +3,8 @@ 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" "github.com/microsoft/typescript-go/internal/testutil" ) @@ -16,5 +16,5 @@ func TestRenameModuleExportsProperties1(t *testing.T) { 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]) } diff --git a/internal/fourslash/tests/gen/renameModuleExportsProperties3_test.go b/internal/fourslash/tests/gen/renameModuleExportsProperties3_test.go index 8c3e219207..35eca115e1 100644 --- a/internal/fourslash/tests/gen/renameModuleExportsProperties3_test.go +++ b/internal/fourslash/tests/gen/renameModuleExportsProperties3_test.go @@ -3,8 +3,8 @@ 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" "github.com/microsoft/typescript-go/internal/testutil" ) @@ -18,5 +18,5 @@ func TestRenameModuleExportsProperties3(t *testing.T) { [|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]) } diff --git a/internal/fourslash/tests/gen/renameNamedImport_test.go b/internal/fourslash/tests/gen/renameNamedImport_test.go index 71524eaf77..7a9df3f016 100644 --- a/internal/fourslash/tests/gen/renameNamedImport_test.go +++ b/internal/fourslash/tests/gen/renameNamedImport_test.go @@ -3,8 +3,8 @@ 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" "github.com/microsoft/typescript-go/internal/testutil" ) @@ -28,5 +28,5 @@ someExportedVariable; 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") } diff --git a/internal/fourslash/tests/gen/renameNumericalIndexSingleQuoted_test.go b/internal/fourslash/tests/gen/renameNumericalIndexSingleQuoted_test.go index ecef90cedf..f02f765d71 100644 --- a/internal/fourslash/tests/gen/renameNumericalIndexSingleQuoted_test.go +++ b/internal/fourslash/tests/gen/renameNumericalIndexSingleQuoted_test.go @@ -4,7 +4,6 @@ import ( "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" ) @@ -16,5 +15,5 @@ func TestRenameNumericalIndexSingleQuoted(t *testing.T) { 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") } diff --git a/internal/fourslash/tests/gen/renameRestBindingElement_test.go b/internal/fourslash/tests/gen/renameRestBindingElement_test.go index 31ea3a77aa..c4c4200e56 100644 --- a/internal/fourslash/tests/gen/renameRestBindingElement_test.go +++ b/internal/fourslash/tests/gen/renameRestBindingElement_test.go @@ -3,8 +3,8 @@ 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" "github.com/microsoft/typescript-go/internal/testutil" ) @@ -22,5 +22,5 @@ function foo([|{ a, ...[|{| "contextRangeIndex": 0 |}rest|] }: I|]) { [|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]) } diff --git a/internal/ls/autoimportfixes.go b/internal/ls/autoimportfixes.go index 907f74d238..ca5c05eda4 100644 --- a/internal/ls/autoimportfixes.go +++ b/internal/ls/autoimportfixes.go @@ -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 @@ -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 } diff --git a/internal/ls/completions.go b/internal/ls/completions.go index 6966553a1e..820b131203 100644 --- a/internal/ls/completions.go +++ b/internal/ls/completions.go @@ -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, } @@ -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 @@ -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 { @@ -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) @@ -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) @@ -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+ @@ -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 @@ -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() || @@ -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 @@ -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{} } diff --git a/internal/ls/types.go b/internal/ls/types.go deleted file mode 100644 index f5f9d19014..0000000000 --- a/internal/ls/types.go +++ /dev/null @@ -1,67 +0,0 @@ -package ls - -import ( - "github.com/microsoft/typescript-go/internal/modulespecifiers" -) - -type JsxAttributeCompletionStyle string - -const ( - JsxAttributeCompletionStyleAuto JsxAttributeCompletionStyle = "auto" - JsxAttributeCompletionStyleBraces JsxAttributeCompletionStyle = "braces" - JsxAttributeCompletionStyleNone JsxAttributeCompletionStyle = "none" -) - -type QuotePreference string - -const ( - QuotePreferenceAuto QuotePreference = "auto" - QuotePreferenceDouble QuotePreference = "double" - QuotePreferenceSingle QuotePreference = "single" -) - -type UserPreferences struct { - QuotePreference *QuotePreference - // If enabled, TypeScript will search through all external modules' exports and add them to the completions list. - // This affects lone identifier completions but not completions on the right hand side of `obj.`. - IncludeCompletionsForModuleExports *bool - - // Enables auto-import-style completions on partially-typed import statements. E.g., allows - // `import write|` to be completed to `import { writeFile } from "fs"`. - IncludeCompletionsForImportStatements *bool - - // Unless this option is `false`, member completion lists triggered with `.` will include entries - // on potentially-null and potentially-undefined values, with insertion text to replace - // preceding `.` tokens with `?.`. - IncludeAutomaticOptionalChainCompletions *bool - - // If enabled, completions for class members (e.g. methods and properties) will include - // a whole declaration for the member. - // E.g., `class A { f| }` could be completed to `class A { foo(): number {} }`, instead of - // `class A { foo }`. - IncludeCompletionsWithClassMemberSnippets *bool - - // If enabled, object literal methods will have a method declaration completion entry in addition - // to the regular completion entry containing just the method name. - // E.g., `const objectLiteral: T = { f| }` could be completed to `const objectLiteral: T = { foo(): void {} }`, - // in addition to `const objectLiteral: T = { foo }`. - IncludeCompletionsWithObjectLiteralMethodSnippets *bool - - JsxAttributeCompletionStyle *JsxAttributeCompletionStyle - - ImportModuleSpecifierPreference modulespecifiers.ImportModuleSpecifierPreference - ImportModuleSpecifierEndingPreference modulespecifiers.ImportModuleSpecifierEndingPreference - PreferTypeOnlyAutoImports *bool - AutoImportSpecifierExcludeRegexes []string - AutoImportFileExcludePatterns []string - - UseAliasesForRename *bool -} - -func (p *UserPreferences) ModuleSpecifierPreferences() modulespecifiers.UserPreferences { - return modulespecifiers.UserPreferences{ - ImportModuleSpecifierPreference: p.ImportModuleSpecifierPreference, - ImportModuleSpecifierEndingPreference: p.ImportModuleSpecifierEndingPreference, - AutoImportSpecifierExcludeRegexes: p.AutoImportSpecifierExcludeRegexes, - } -} diff --git a/internal/ls/userpreferences.go b/internal/ls/userpreferences.go new file mode 100644 index 0000000000..11be04d64a --- /dev/null +++ b/internal/ls/userpreferences.go @@ -0,0 +1,211 @@ +package ls + +import ( + "github.com/microsoft/typescript-go/internal/core" + "github.com/microsoft/typescript-go/internal/modulespecifiers" +) + +type UserPreferences struct { + QuotePreference QuotePreference + LazyConfiguredProjectsFromExternalProject bool // !!! + + // A positive integer indicating the maximum length of a hover text before it is truncated. + // + // Default: `500` + MaximumHoverLength int // !!! + + // ------- Completions ------- + + // If enabled, TypeScript will search through all external modules' exports and add them to the completions list. + // This affects lone identifier completions but not completions on the right hand side of `obj.`. + IncludeCompletionsForModuleExports core.Tristate + // Enables auto-import-style completions on partially-typed import statements. E.g., allows + // `import write|` to be completed to `import { writeFile } from "fs"`. + IncludeCompletionsForImportStatements core.Tristate + // Unless this option is `false`, member completion lists triggered with `.` will include entries + // on potentially-null and potentially-undefined values, with insertion text to replace + // preceding `.` tokens with `?.`. + IncludeAutomaticOptionalChainCompletions core.Tristate + // Allows completions to be formatted with snippet text, indicated by `CompletionItem["isSnippet"]`. + IncludeCompletionsWithSnippetText core.Tristate // !!! + // If enabled, completions for class members (e.g. methods and properties) will include + // a whole declaration for the member. + // E.g., `class A { f| }` could be completed to `class A { foo(): number {} }`, instead of + // `class A { foo }`. + IncludeCompletionsWithClassMemberSnippets core.Tristate // !!! + // If enabled, object literal methods will have a method declaration completion entry in addition + // to the regular completion entry containing just the method name. + // E.g., `const objectLiteral: T = { f| }` could be completed to `const objectLiteral: T = { foo(): void {} }`, + // in addition to `const objectLiteral: T = { foo }`. + IncludeCompletionsWithObjectLiteralMethodSnippets core.Tristate // !!! + JsxAttributeCompletionStyle JsxAttributeCompletionStyle + + // ------- AutoImports -------- + + ImportModuleSpecifierPreference modulespecifiers.ImportModuleSpecifierPreference // !!! + // Determines whether we import `foo/index.ts` as "foo", "foo/index", or "foo/index.js" + ImportModuleSpecifierEnding modulespecifiers.ImportModuleSpecifierEndingPreference // !!! + IncludePackageJsonAutoImports IncludePackageJsonAutoImports // !!! + AutoImportSpecifierExcludeRegexes []string // !!! + AutoImportFileExcludePatterns []string // !!! + PreferTypeOnlyAutoImports bool // !!! + + // ------- OrganizeImports ------- + + // Indicates whether imports should be organized in a case-insensitive manner. + // + // Default: TSUnknown ("auto" in strada), will perform detection + OrganizeImportsIgnoreCase core.Tristate // !!! + // Indicates whether imports should be organized via an "ordinal" (binary) comparison using the numeric value of their + // code points, or via "unicode" collation (via the Unicode Collation Algorithm (https://unicode.org/reports/tr10/#Scope)) + // + // using rules associated with the locale specified in organizeImportsCollationLocale. + // + // Default: Ordinal + OrganizeImportsCollation OrganizeImportsCollation // !!! + // Indicates the locale to use for "unicode" collation. If not specified, the locale `"en"` is used as an invariant + // for the sake of consistent sorting. Use `"auto"` to use the detected UI locale. + // + // This preference is ignored if organizeImportsCollation is not `unicode`. + // + // Default: `"en"` + OrganizeImportsLocale string // !!! + // Indicates whether numeric collation should be used for digit sequences in strings. When `true`, will collate + // strings such that `a1z < a2z < a100z`. When `false`, will collate strings such that `a1z < a100z < a2z`. + // + // This preference is ignored if organizeImportsCollation is not `unicode`. + // + // Default: `false` + OrganizeImportsNumericCollation bool // !!! + // Indicates whether accents and other diacritic marks are considered unequal for the purpose of collation. When + // `true`, characters with accents and other diacritics will be collated in the order defined by the locale specified + // in organizeImportsCollationLocale. + // + // This preference is ignored if organizeImportsCollation is not `unicode`. + // + // Default: `true` + OrganizeImportsAccentCollation OrganizeImportsAccentCollation // !!! + // Indicates whether upper case or lower case should sort first. When `false`, the default order for the locale + // specified in organizeImportsCollationLocale is used. + // + // This preference is ignored if: + // - organizeImportsCollation is not `unicode` + // - organizeImportsIgnoreCase is `true` + // - organizeImportsIgnoreCase is `auto` and the auto-detected case sensitivity is case-insensitive. + // + // Default: `false` + OrganizeImportsCaseFirst OrganizeImportsCaseFirst // !!! + // Indicates where named type-only imports should sort. "inline" sorts named imports without regard to if the import is type-only. + // + // Default: `last` + OrganizeImportsTypeOrder OrganizeImportsTypeOrder // !!! + + // ------- MoveToFile ------- + + AllowTextChangesInNewFiles bool // !!! + + // ------- Rename ------- + + // renamed from `providePrefixAndSuffixTextForRename` + UseAliasesForRename core.Tristate + AllowRenameOfImportPath bool // !!! + + // ------- CodeFixes/Refactors ------- + + ProvideRefactorNotApplicableReason bool // !!! + + // ------- InlayHints ------- + + IncludeInlayParameterNameHints IncludeInlayParameterNameHints + IncludeInlayParameterNameHintsWhenArgumentMatchesName bool + IncludeInlayFunctionParameterTypeHints bool + IncludeInlayVariableTypeHints bool + IncludeInlayVariableTypeHintsWhenTypeMatchesName bool + IncludeInlayPropertyDeclarationTypeHints bool + IncludeInlayFunctionLikeReturnTypeHints bool + IncludeInlayEnumMemberValueHints bool + InteractiveInlayHints bool + + // ------- Misc ------- + + ExcludeLibrarySymbolsInNavTo bool // !!! + DisableSuggestions bool // !!! + DisableLineTextInReferences bool // !!! + DisplayPartsForJSDoc bool // !!! +} + +type JsxAttributeCompletionStyle string + +const ( + JsxAttributeCompletionStyleUnknown JsxAttributeCompletionStyle = "" + JsxAttributeCompletionStyleAuto JsxAttributeCompletionStyle = "auto" + JsxAttributeCompletionStyleBraces JsxAttributeCompletionStyle = "braces" + JsxAttributeCompletionStyleNone JsxAttributeCompletionStyle = "none" +) + +type IncludeInlayParameterNameHints string + +const ( + IncludeInlayParameterNameHintsNone IncludeInlayParameterNameHints = "" + IncludeInlayParameterNameHintsAll IncludeInlayParameterNameHints = "all" + IncludeInlayParameterNameHintsLiterals IncludeInlayParameterNameHints = "literals" +) + +type IncludePackageJsonAutoImports string + +const ( + IncludePackageJsonAutoImportsUnknown IncludePackageJsonAutoImports = "" + IncludePackageJsonAutoImportsAuto IncludePackageJsonAutoImports = "auto" + IncludePackageJsonAutoImportsOn IncludePackageJsonAutoImports = "on" + IncludePackageJsonAutoImportsOff IncludePackageJsonAutoImports = "off" +) + +type OrganizeImportsCollation bool + +const ( + OrganizeImportsCollationOrdinal OrganizeImportsCollation = false + OrganizeImportsCollationUnicode OrganizeImportsCollation = true +) + +type OrganizeImportsAccentCollation int + +const ( + OrganizeImportsAccentCollationTrue OrganizeImportsAccentCollation = 0 + OrganizeImportsAccentCollationFalse OrganizeImportsAccentCollation = 1 +) + +type OrganizeImportsCaseFirst int + +const ( + OrganizeImportsCaseFirstFalse OrganizeImportsCaseFirst = 0 + OrganizeImportsCaseFirstLower OrganizeImportsCaseFirst = 1 + OrganizeImportsCaseFirstUpper OrganizeImportsCaseFirst = 2 +) + +type OrganizeImportsTypeOrder int + +const ( + OrganizeImportsTypeOrderLast OrganizeImportsTypeOrder = 0 + OrganizeImportsTypeOrderInline OrganizeImportsTypeOrder = 1 + OrganizeImportsTypeOrderFirst OrganizeImportsTypeOrder = 2 +) + +type QuotePreference string + +const ( + QuotePreferenceUnknown QuotePreference = "" + QuotePreferenceAuto QuotePreference = "auto" + QuotePreferenceDouble QuotePreference = "double" + QuotePreferenceSingle QuotePreference = "single" +) + +func (p *UserPreferences) Parse(config map[string]interface{}) { +} + +func (p *UserPreferences) ModuleSpecifierPreferences() modulespecifiers.UserPreferences { + return modulespecifiers.UserPreferences{ + ImportModuleSpecifierPreference: p.ImportModuleSpecifierPreference, + ImportModuleSpecifierEnding: p.ImportModuleSpecifierEnding, + AutoImportSpecifierExcludeRegexes: p.AutoImportSpecifierExcludeRegexes, + } +} diff --git a/internal/lsp/server.go b/internal/lsp/server.go index 62d3baa28c..6c3478ae3d 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -770,8 +770,8 @@ func (s *Server) handleCompletion(ctx context.Context, languageService *ls.Langu params.Context, getCompletionClientCapabilities(s.initializeParams), &ls.UserPreferences{ - IncludeCompletionsForModuleExports: ptrTo(true), - IncludeCompletionsForImportStatements: ptrTo(true), + IncludeCompletionsForModuleExports: core.TSTrue, + IncludeCompletionsForImportStatements: core.TSTrue, }) } @@ -791,8 +791,8 @@ func (s *Server) handleCompletionItemResolve(ctx context.Context, params *lsprot data, getCompletionClientCapabilities(s.initializeParams), &ls.UserPreferences{ - IncludeCompletionsForModuleExports: ptrTo(true), - IncludeCompletionsForImportStatements: ptrTo(true), + IncludeCompletionsForModuleExports: core.TSTrue, + IncludeCompletionsForImportStatements: core.TSTrue, }, ) } diff --git a/internal/modulespecifiers/preferences.go b/internal/modulespecifiers/preferences.go index 226335fdbb..f28f1293c6 100644 --- a/internal/modulespecifiers/preferences.go +++ b/internal/modulespecifiers/preferences.go @@ -131,7 +131,7 @@ func getPreferredEnding( resolutionMode = host.GetDefaultResolutionModeForFile(importingSourceFile) } return getModuleSpecifierEndingPreference( - prefs.ImportModuleSpecifierEndingPreference, + prefs.ImportModuleSpecifierEnding, resolutionMode, compilerOptions, importingSourceFile, diff --git a/internal/modulespecifiers/types.go b/internal/modulespecifiers/types.go index eb9881f656..6cdfa3e689 100644 --- a/internal/modulespecifiers/types.go +++ b/internal/modulespecifiers/types.go @@ -86,9 +86,9 @@ const ( ) type UserPreferences struct { - ImportModuleSpecifierPreference ImportModuleSpecifierPreference - ImportModuleSpecifierEndingPreference ImportModuleSpecifierEndingPreference - AutoImportSpecifierExcludeRegexes []string + ImportModuleSpecifierPreference ImportModuleSpecifierPreference + ImportModuleSpecifierEnding ImportModuleSpecifierEndingPreference + AutoImportSpecifierExcludeRegexes []string } type ModuleSpecifierOptions struct {