lsutil

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func AssertHasRealPosition

func AssertHasRealPosition(node *ast.Node)

func CompareImportsOrRequireStatements

func CompareImportsOrRequireStatements(s1 *ast.Statement, s2 *ast.Statement, comparer func(a, b string) int) int

CompareImportsOrRequireStatements compares two import or require statements.

func CompareModuleSpecifiers

func CompareModuleSpecifiers(m1 *ast.Expression, m2 *ast.Expression, comparer func(a, b string) int) int

CompareModuleSpecifiers compares two module specifiers using the given comparer.

func DetectModuleSpecifierCaseBySort

func DetectModuleSpecifierCaseBySort(importDeclsByGroup [][]*ast.Statement, comparersToTest []func(a, b string) int) (comparer func(a, b string) int, isSorted bool)

DetectModuleSpecifierCaseBySort detects the order of module specifiers based on import statements throughout the module/file

func FilterImportDeclarations

func FilterImportDeclarations(statements []*ast.Statement) []*ast.Statement

FilterImportDeclarations filters out non-import declarations from a list of statements.

func GetExternalModuleName

func GetExternalModuleName(specifier *ast.Expression) string

GetExternalModuleName returns the module name from a module specifier expression.

func GetFirstToken

func GetFirstToken(node *ast.Node, sourceFile *ast.SourceFile) *ast.Node

func GetImportDeclarationInsertIndex

func GetImportDeclarationInsertIndex(sortedImports []*ast.Statement, newImport *ast.Statement, comparer func(a, b *ast.Statement) int) int

GetImportDeclarationInsertIndex returns the index at which to insert a new import declaration.

func GetImportSpecifierInsertionIndex

func GetImportSpecifierInsertionIndex(sortedImports []*ast.Node, newImport *ast.Node, comparer func(s1, s2 *ast.Node) int) int

GetImportSpecifierInsertionIndex returns the index at which to insert a new import specifier.

func GetLastChild

func GetLastChild(node *ast.Node, sourceFile *ast.SourceFile) *ast.Node

Replaces last(node.getChildren(sourceFile))

func GetLastToken

func GetLastToken(node *ast.Node, sourceFile *ast.SourceFile) *ast.Node

func GetLastVisitedChild

func GetLastVisitedChild(node *ast.Node, sourceFile *ast.SourceFile) *ast.Node

Gets the last visited child of the given node. NOTE: This doesn't include unvisited tokens; for this, use `getLastChild` or `getLastToken`.

func GetNamedImportSpecifierComparer

func GetNamedImportSpecifierComparer(preferences UserPreferences, comparer func(a, b string) int) func(s1, s2 *ast.Node) int

GetNamedImportSpecifierComparer returns a comparer function for sorting import specifiers.

func GetNamedImportSpecifierComparerWithDetection

func GetNamedImportSpecifierComparerWithDetection(importDecl *ast.Node, sourceFile *ast.SourceFile, preferences UserPreferences) (specifierComparer func(s1, s2 *ast.Node) int, isSorted core.Tristate)

GetNamedImportSpecifierComparerWithDetection returns a specifier comparer based on detecting the existing sort order within a single import statement

func GetOrganizeImportsStringComparerWithDetection

func GetOrganizeImportsStringComparerWithDetection(originalImportDecls []*ast.Statement, preferences UserPreferences) (comparer func(a, b string) int, isSorted bool)

GetOrganizeImportsStringComparerWithDetection returns a string comparer based on detecting the order of import statements by the module specifier

func IsCompletedNode

func IsCompletedNode(n *ast.Node, sourceFile *ast.SourceFile) bool

func IsNonContextualKeyword

func IsNonContextualKeyword(token ast.Kind) bool

func ModuleSpecifierToValidIdentifier

func ModuleSpecifierToValidIdentifier(moduleSpecifier string, forceCapitalize bool) string

func ModuleSymbolToValidIdentifier

func ModuleSymbolToValidIdentifier(moduleSymbol *ast.Symbol, forceCapitalize bool) string

func NodeIsASICandidate

func NodeIsASICandidate(node *ast.Node, file *ast.SourceFile) bool

func PositionBelongsToNode

func PositionBelongsToNode(candidate *ast.Node, position int, file *ast.SourceFile) bool

PositionBelongsToNode returns true if the position belongs to the node. Assumes `candidate.Pos() <= position` holds.

func PositionIsASICandidate

func PositionIsASICandidate(pos int, context *ast.Node, file *ast.SourceFile) bool

func ProbablyUsesSemicolons

func ProbablyUsesSemicolons(file *ast.SourceFile) bool

func ShouldUseUriStyleNodeCoreModules

func ShouldUseUriStyleNodeCoreModules(file *ast.SourceFile, program *compiler.Program) core.Tristate

func SyntaxMayBeASICandidate

func SyntaxMayBeASICandidate(kind ast.Kind) bool

func SyntaxRequiresTrailingCommaOrSemicolonOrASI

func SyntaxRequiresTrailingCommaOrSemicolonOrASI(kind ast.Kind) bool

func SyntaxRequiresTrailingFunctionBlockOrSemicolonOrASI

func SyntaxRequiresTrailingFunctionBlockOrSemicolonOrASI(kind ast.Kind) bool

func SyntaxRequiresTrailingModuleBlockOrSemicolonOrASI

func SyntaxRequiresTrailingModuleBlockOrSemicolonOrASI(kind ast.Kind) bool

func SyntaxRequiresTrailingSemicolonOrASI

func SyntaxRequiresTrailingSemicolonOrASI(kind ast.Kind) bool

Types

type CodeLensUserPreferences

type CodeLensUserPreferences struct {
	ReferencesCodeLensEnabled                     core.Tristate `raw:"referencesCodeLensEnabled" config:"referencesCodeLens.enabled"`
	ImplementationsCodeLensEnabled                core.Tristate `raw:"implementationsCodeLensEnabled" config:"implementationsCodeLens.enabled"`
	ReferencesCodeLensShowOnAllFunctions          core.Tristate `raw:"referencesCodeLensShowOnAllFunctions" config:"referencesCodeLens.showOnAllFunctions"`
	ImplementationsCodeLensShowOnInterfaceMethods core.Tristate `raw:"implementationsCodeLensShowOnInterfaceMethods" config:"implementationsCodeLens.showOnInterfaceMethods"`
	ImplementationsCodeLensShowOnAllClassMethods  core.Tristate `raw:"implementationsCodeLensShowOnAllClassMethods" config:"implementationsCodeLens.showOnAllClassMethods"`
}

type EditorSettings

type EditorSettings struct {
	BaseIndentSize         int           `raw:"baseIndentSize" config:"format.baseIndentSize"`
	IndentSize             int           `raw:"indentSize" config:"format.indentSize"`
	TabSize                int           `raw:"tabSize" config:"format.tabSize"`
	NewLineCharacter       string        `raw:"newLineCharacter" config:"format.newLineCharacter"`
	ConvertTabsToSpaces    core.Tristate `raw:"convertTabsToSpaces" config:"format.convertTabsToSpaces"`
	IndentStyle            IndentStyle   `raw:"indentStyle" config:"format.indentStyle"`
	TrimTrailingWhitespace core.Tristate `raw:"trimTrailingWhitespace" config:"format.trimTrailingWhitespace"`
}

type FormatCodeSettings

type FormatCodeSettings struct {
	EditorSettings
	InsertSpaceAfterCommaDelimiter                              core.Tristate       `raw:"insertSpaceAfterCommaDelimiter" config:"format.insertSpaceAfterCommaDelimiter"`
	InsertSpaceAfterSemicolonInForStatements                    core.Tristate       `raw:"insertSpaceAfterSemicolonInForStatements" config:"format.insertSpaceAfterSemicolonInForStatements"`
	InsertSpaceBeforeAndAfterBinaryOperators                    core.Tristate       `raw:"insertSpaceBeforeAndAfterBinaryOperators" config:"format.insertSpaceBeforeAndAfterBinaryOperators"`
	InsertSpaceAfterConstructor                                 core.Tristate       `raw:"insertSpaceAfterConstructor" config:"format.insertSpaceAfterConstructor"`
	InsertSpaceAfterKeywordsInControlFlowStatements             core.Tristate       `raw:"insertSpaceAfterKeywordsInControlFlowStatements" config:"format.insertSpaceAfterKeywordsInControlFlowStatements"`
	InsertSpaceAfterFunctionKeywordForAnonymousFunctions        core.Tristate       `` /* 127-byte string literal not displayed */
	InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis  core.Tristate       `` /* 139-byte string literal not displayed */
	InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets     core.Tristate       `` /* 133-byte string literal not displayed */
	InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces       core.Tristate       `` /* 129-byte string literal not displayed */
	InsertSpaceAfterOpeningAndBeforeClosingEmptyBraces          core.Tristate       `raw:"insertSpaceAfterOpeningAndBeforeClosingEmptyBraces" config:"format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces"`
	InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces core.Tristate       `` /* 141-byte string literal not displayed */
	InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces  core.Tristate       `` /* 139-byte string literal not displayed */
	InsertSpaceAfterTypeAssertion                               core.Tristate       `raw:"insertSpaceAfterTypeAssertion" config:"format.insertSpaceAfterTypeAssertion"`
	InsertSpaceBeforeFunctionParenthesis                        core.Tristate       `raw:"insertSpaceBeforeFunctionParenthesis" config:"format.insertSpaceBeforeFunctionParenthesis"`
	PlaceOpenBraceOnNewLineForFunctions                         core.Tristate       `raw:"placeOpenBraceOnNewLineForFunctions" config:"format.placeOpenBraceOnNewLineForFunctions"`
	PlaceOpenBraceOnNewLineForControlBlocks                     core.Tristate       `raw:"placeOpenBraceOnNewLineForControlBlocks" config:"format.placeOpenBraceOnNewLineForControlBlocks"`
	InsertSpaceBeforeTypeAnnotation                             core.Tristate       `raw:"insertSpaceBeforeTypeAnnotation" config:"format.insertSpaceBeforeTypeAnnotation"`
	IndentMultiLineObjectLiteralBeginningOnBlankLine            core.Tristate       `raw:"indentMultiLineObjectLiteralBeginningOnBlankLine" config:"format.indentMultiLineObjectLiteralBeginningOnBlankLine"`
	Semicolons                                                  SemicolonPreference `raw:"semicolons" config:"format.semicolons"`
	IndentSwitchCase                                            core.Tristate       `raw:"indentSwitchCase" config:"format.indentSwitchCase"`
}

func GetDefaultFormatCodeSettings

func GetDefaultFormatCodeSettings() FormatCodeSettings

func (FormatCodeSettings) ToLSFormatOptions

func (settings FormatCodeSettings) ToLSFormatOptions() *lsproto.FormattingOptions

type IncludeInlayParameterNameHints

type IncludeInlayParameterNameHints string
const (
	IncludeInlayParameterNameHintsNone     IncludeInlayParameterNameHints = ""
	IncludeInlayParameterNameHintsAll      IncludeInlayParameterNameHints = "all"
	IncludeInlayParameterNameHintsLiterals IncludeInlayParameterNameHints = "literals"
)

type IncludePackageJsonAutoImports

type IncludePackageJsonAutoImports string
const (
	IncludePackageJsonAutoImportsUnknown IncludePackageJsonAutoImports = ""
	IncludePackageJsonAutoImportsAuto    IncludePackageJsonAutoImports = "auto"
	IncludePackageJsonAutoImportsOn      IncludePackageJsonAutoImports = "on"
	IncludePackageJsonAutoImportsOff     IncludePackageJsonAutoImports = "off"
)

type IndentStyle

type IndentStyle int
const (
	IndentStyleNone IndentStyle = iota
	IndentStyleBlock
	IndentStyleSmart
)

type InlayHintsPreferences

type InlayHintsPreferences struct {
	IncludeInlayParameterNameHints                        IncludeInlayParameterNameHints `raw:"includeInlayParameterNameHints" config:"inlayHints.parameterNames.enabled"`
	IncludeInlayParameterNameHintsWhenArgumentMatchesName core.Tristate                  `` /* 133-byte string literal not displayed */
	IncludeInlayFunctionParameterTypeHints                core.Tristate                  `raw:"includeInlayFunctionParameterTypeHints" config:"inlayHints.parameterTypes.enabled"`
	IncludeInlayVariableTypeHints                         core.Tristate                  `raw:"includeInlayVariableTypeHints" config:"inlayHints.variableTypes.enabled"`
	IncludeInlayVariableTypeHintsWhenTypeMatchesName      core.Tristate                  `raw:"includeInlayVariableTypeHintsWhenTypeMatchesName" config:"inlayHints.variableTypes.suppressWhenTypeMatchesName,invert"`
	IncludeInlayPropertyDeclarationTypeHints              core.Tristate                  `raw:"includeInlayPropertyDeclarationTypeHints" config:"inlayHints.propertyDeclarationTypes.enabled"`
	IncludeInlayFunctionLikeReturnTypeHints               core.Tristate                  `raw:"includeInlayFunctionLikeReturnTypeHints" config:"inlayHints.functionLikeReturnTypes.enabled"`
	IncludeInlayEnumMemberValueHints                      core.Tristate                  `raw:"includeInlayEnumMemberValueHints" config:"inlayHints.enumMemberValues.enabled"`
}

type JsxAttributeCompletionStyle

type JsxAttributeCompletionStyle string
const (
	JsxAttributeCompletionStyleUnknown JsxAttributeCompletionStyle = ""
	JsxAttributeCompletionStyleAuto    JsxAttributeCompletionStyle = "auto"
	JsxAttributeCompletionStyleBraces  JsxAttributeCompletionStyle = "braces"
	JsxAttributeCompletionStyleNone    JsxAttributeCompletionStyle = "none"
)

type OrganizeImportsCaseFirst

type OrganizeImportsCaseFirst int
const (
	OrganizeImportsCaseFirstFalse OrganizeImportsCaseFirst = 0
	OrganizeImportsCaseFirstLower OrganizeImportsCaseFirst = 1
	OrganizeImportsCaseFirstUpper OrganizeImportsCaseFirst = 2
)

type OrganizeImportsCollation

type OrganizeImportsCollation bool
const (
	OrganizeImportsCollationOrdinal OrganizeImportsCollation = false
	OrganizeImportsCollationUnicode OrganizeImportsCollation = true
)

type OrganizeImportsTypeOrder

type OrganizeImportsTypeOrder int
const (
	OrganizeImportsTypeOrderAuto   OrganizeImportsTypeOrder = 0
	OrganizeImportsTypeOrderLast   OrganizeImportsTypeOrder = 1
	OrganizeImportsTypeOrderInline OrganizeImportsTypeOrder = 2
	OrganizeImportsTypeOrderFirst  OrganizeImportsTypeOrder = 3
)

func DetectNamedImportOrganizationBySort

func DetectNamedImportOrganizationBySort(
	originalGroups []*ast.Statement,
	comparersToTest []func(a, b string) int,
	typesToTest []OrganizeImportsTypeOrder,
) (comparer func(a, b string) int, typeOrder OrganizeImportsTypeOrder, found bool)

DetectNamedImportOrganizationBySort detects the order of named imports throughout the file by considering the named imports in each statement as a group

func GetDetectionLists

func GetDetectionLists(preferences UserPreferences) (comparersToTest []func(a, b string) int, typeOrdersToTest []OrganizeImportsTypeOrder)

GetDetectionLists returns the lists of comparers and type orders to test for organize imports detection.

type QuotePreference

type QuotePreference string
const (
	QuotePreferenceUnknown QuotePreference = ""
	QuotePreferenceAuto    QuotePreference = "auto"
	QuotePreferenceDouble  QuotePreference = "double"
	QuotePreferenceSingle  QuotePreference = "single"
)

func GetQuotePreference

func GetQuotePreference(sourceFile *ast.SourceFile, preferences UserPreferences) QuotePreference

func QuotePreferenceFromString

func QuotePreferenceFromString(str *ast.StringLiteral) QuotePreference

type ScriptElementKind

type ScriptElementKind int
const (
	ScriptElementKindUnknown ScriptElementKind = iota
	ScriptElementKindWarning
	// predefined type (void) or keyword (class)
	ScriptElementKindKeyword
	// top level script node
	ScriptElementKindScriptElement
	// module foo {}
	ScriptElementKindModuleElement
	// class X {}
	ScriptElementKindClassElement
	// var x = class X {}
	ScriptElementKindLocalClassElement
	// interface Y {}
	ScriptElementKindInterfaceElement
	// type T = ...
	ScriptElementKindTypeElement
	// enum E {}
	ScriptElementKindEnumElement
	ScriptElementKindEnumMemberElement
	// Inside module and script only.
	// const v = ...
	ScriptElementKindVariableElement
	// Inside function.
	ScriptElementKindLocalVariableElement
	// using foo = ...
	ScriptElementKindVariableUsingElement
	// await using foo = ...
	ScriptElementKindVariableAwaitUsingElement
	// Inside module and script only.
	// function f() {}
	ScriptElementKindFunctionElement
	// Inside function.
	ScriptElementKindLocalFunctionElement
	// class X { [public|private]* foo() {} }
	ScriptElementKindMemberFunctionElement
	// class X { [public|private]* [get|set] foo:number; }
	ScriptElementKindMemberGetAccessorElement
	ScriptElementKindMemberSetAccessorElement
	// class X { [public|private]* foo:number; }
	// interface Y { foo:number; }
	ScriptElementKindMemberVariableElement
	// class X { [public|private]* accessor foo: number; }
	ScriptElementKindMemberAccessorVariableElement
	// class X { constructor() { } }
	// class X { static { } }
	ScriptElementKindConstructorImplementationElement
	// interface Y { ():number; }
	ScriptElementKindCallSignatureElement
	// interface Y { []:number; }
	ScriptElementKindIndexSignatureElement
	// interface Y { new():Y; }
	ScriptElementKindConstructSignatureElement
	// function foo(*Y*: string)
	ScriptElementKindParameterElement
	ScriptElementKindTypeParameterElement
	ScriptElementKindPrimitiveType
	ScriptElementKindLabel
	ScriptElementKindAlias
	ScriptElementKindConstElement
	ScriptElementKindLetElement
	ScriptElementKindDirectory
	ScriptElementKindExternalModuleName
	// String literal
	ScriptElementKindString
	// Jsdoc @link: in `{@link C link text}`, the before and after text "{@link " and "}"
	ScriptElementKindLink
	// Jsdoc @link: in `{@link C link text}`, the entity name "C"
	ScriptElementKindLinkName
	// Jsdoc @link: in `{@link C link text}`, the link text "link text"
	ScriptElementKindLinkText
)

func GetSymbolKind

func GetSymbolKind(typeChecker *checker.Checker, symbol *ast.Symbol, location *ast.Node) ScriptElementKind

type ScriptElementKindModifier

type ScriptElementKindModifier uint32
const (
	ScriptElementKindModifierNone   ScriptElementKindModifier = 0
	ScriptElementKindModifierPublic ScriptElementKindModifier = 1 << iota
	ScriptElementKindModifierPrivate
	ScriptElementKindModifierProtected
	ScriptElementKindModifierExported
	ScriptElementKindModifierAmbient
	ScriptElementKindModifierStatic
	ScriptElementKindModifierAbstract
	ScriptElementKindModifierOptional
	ScriptElementKindModifierDeprecated
	ScriptElementKindModifierDts
	ScriptElementKindModifierTs
	ScriptElementKindModifierTsx
	ScriptElementKindModifierJs
	ScriptElementKindModifierJsx
	ScriptElementKindModifierJson
	ScriptElementKindModifierDmts
	ScriptElementKindModifierMts
	ScriptElementKindModifierMjs
	ScriptElementKindModifierDcts
	ScriptElementKindModifierCts
	ScriptElementKindModifierCjs
)

func GetSymbolModifiers

func GetSymbolModifiers(typeChecker *checker.Checker, symbol *ast.Symbol) ScriptElementKindModifier

func (ScriptElementKindModifier) Strings

type SemicolonPreference

type SemicolonPreference string
const (
	SemicolonPreferenceIgnore SemicolonPreference = "ignore"
	SemicolonPreferenceInsert SemicolonPreference = "insert"
	SemicolonPreferenceRemove SemicolonPreference = "remove"
)

type UserPreferences

type UserPreferences struct {
	FormatCodeSettings FormatCodeSettings

	QuotePreference                           QuotePreference `raw:"quotePreference" config:"preferences.quoteStyle"`
	LazyConfiguredProjectsFromExternalProject core.Tristate   `raw:"lazyConfiguredProjectsFromExternalProject"` // !!!

	// A positive integer indicating the maximum length of a hover text before it is truncated.
	//
	// Default: `500`
	MaximumHoverLength int `raw:"maximumHoverLength"` // !!!

	// 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 `raw:"includeCompletionsForModuleExports" config:"suggest.autoImports"`
	// 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 `raw:"includeCompletionsForImportStatements" config:"suggest.includeCompletionsForImportStatements"`
	// 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 `raw:"includeAutomaticOptionalChainCompletions" config:"suggest.includeAutomaticOptionalChainCompletions"`
	// 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 `raw:"includeCompletionsWithClassMemberSnippets" config:"suggest.classMemberSnippets.enabled"` // !!!
	// 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               `raw:"includeCompletionsWithObjectLiteralMethodSnippets" config:"suggest.objectLiteralMethodSnippets.enabled"` // !!!
	JsxAttributeCompletionStyle                       JsxAttributeCompletionStyle `raw:"jsxAttributeCompletionStyle" config:"preferences.jsxAttributeCompletionStyle"`

	ImportModuleSpecifierPreference modulespecifiers.ImportModuleSpecifierPreference `raw:"importModuleSpecifierPreference" config:"preferences.importModuleSpecifier"` // !!!
	// Determines whether we import `foo/index.ts` as "foo", "foo/index", or "foo/index.js"
	ImportModuleSpecifierEnding       modulespecifiers.ImportModuleSpecifierEndingPreference `raw:"importModuleSpecifierEnding" config:"preferences.importModuleSpecifierEnding"`             // !!!
	AutoImportSpecifierExcludeRegexes []string                                               `raw:"autoImportSpecifierExcludeRegexes" config:"preferences.autoImportSpecifierExcludeRegexes"` // !!!
	IncludePackageJsonAutoImports     IncludePackageJsonAutoImports                          `raw:"includePackageJsonAutoImports" config:"preferences.includePackageJsonAutoImports"`
	AutoImportFileExcludePatterns     []string                                               `raw:"autoImportFileExcludePatterns" config:"preferences.autoImportFileExcludePatterns"`
	PreferTypeOnlyAutoImports         core.Tristate                                          `raw:"preferTypeOnlyAutoImports" config:"preferences.preferTypeOnlyAutoImports"`

	// Indicates whether imports should be organized in a case-insensitive manner.
	//
	// Default: TSUnknown ("auto" in strada), will perform detection
	OrganizeImportsIgnoreCase core.Tristate `raw:"organizeImportsIgnoreCase" config:"preferences.organizeImports.caseSensitivity"` // !!!
	// 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 `raw:"organizeImportsCollation" config:"preferences.organizeImports.unicodeCollation"` // !!!
	// 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 `raw:"organizeImportsLocale" config:"preferences.organizeImports.locale"` // !!!
	// 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 core.Tristate `raw:"organizeImportsNumericCollation" config:"preferences.organizeImports.numericCollation"` // !!!
	// 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 core.Tristate `raw:"organizeImportsAccentCollation" config:"preferences.organizeImports.accentCollation"` // !!!
	// Indicates whether upper case or lower case should sort first. When `false`, the default order for the locale
	// specified in organizeImportsCollationLocale is used.
	//
	// This permission 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 `raw:"organizeImportsCaseFirst" config:"preferences.organizeImports.caseFirst"` // !!!
	// Indicates where named type-only imports should sort. "inline" sorts named imports without regard to if the import is type-only.
	//
	// Default: `auto`, which defaults to `last`
	OrganizeImportsTypeOrder OrganizeImportsTypeOrder `raw:"organizeImportsTypeOrder" config:"preferences.organizeImports.typeOrder"` // !!!

	AllowTextChangesInNewFiles core.Tristate `raw:"allowTextChangesInNewFiles"` // !!!

	UseAliasesForRename     core.Tristate `raw:"providePrefixAndSuffixTextForRename" config:"preferences.useAliasesForRenames"`
	AllowRenameOfImportPath core.Tristate `raw:"allowRenameOfImportPath"`

	ProvideRefactorNotApplicableReason core.Tristate `raw:"provideRefactorNotApplicableReason"` // !!!

	InlayHints InlayHintsPreferences

	CodeLens CodeLensUserPreferences

	PreferGoToSourceDefinition bool `raw:"preferGoToSourceDefinition"`

	ExcludeLibrarySymbolsInNavTo core.Tristate `raw:"excludeLibrarySymbolsInNavTo" config:"workspaceSymbols.excludeLibrarySymbols"`

	DisableSuggestions          core.Tristate `raw:"disableSuggestions"`          // !!!
	DisableLineTextInReferences core.Tristate `raw:"disableLineTextInReferences"` // !!!
	DisplayPartsForJSDoc        core.Tristate `raw:"displayPartsForJSDoc"`        // !!!
	ReportStyleChecksAsWarnings core.Tristate `raw:"reportStyleChecksAsWarnings"` // !!! If this changes, we need to ask the client to recompute diagnostics

	// DisableAutomaticTypeAcquisition is the deprecated setting from typescript.disableAutomaticTypeAcquisition.
	DisableAutomaticTypeAcquisition core.Tristate `raw:"disableAutomaticTypeAcquisition" config:"disableAutomaticTypeAcquisition"`
	// AutomaticTypeAcquisitionEnabled is the unified setting from tsserver.automaticTypeAcquisition.enabled under the js/ts section.
	// When set, it takes precedence over DisableAutomaticTypeAcquisition.
	AutomaticTypeAcquisitionEnabled core.Tristate `raw:"automaticTypeAcquisitionEnabled" config:"tsserver.automaticTypeAcquisition.enabled"`

	// CustomConfigFileName specifies a custom config file name to use before defaulting to tsconfig.json/jsconfig.json.
	CustomConfigFileName string `raw:"customConfigFileName" config:"native-preview.customConfigFileName"`
}

UserPreferences represents TypeScript language service preferences.

Fields are populated using two tags:

  • `raw:"name"` or `raw:"name,invert"` - TypeScript/raw name for unstable section lookup
  • `config:"path.to.setting"` or `config:"path.to.setting,invert"` - VS Code nested config path

At least one tag must be present on each preference field. The `,invert` modifier inverts boolean values (e.g., VS Code's "suppress" -> our "include").

func NewDefaultUserPreferences

func NewDefaultUserPreferences() UserPreferences

func ParseUserPreferences

func ParseUserPreferences(items map[string]any) UserPreferences

func (UserPreferences) IsATADisabled added in v0.0.2

func (p UserPreferences) IsATADisabled() bool

IsATADisabled returns whether Automatic Type Acquisition is disabled based on user preferences. It checks the unified setting (tsserver.automaticTypeAcquisition.enabled) first, then falls back to the deprecated setting (disableAutomaticTypeAcquisition).

func (UserPreferences) IsModuleSpecifierExcluded

func (p UserPreferences) IsModuleSpecifierExcluded(moduleSpecifier string) bool

func (*UserPreferences) MarshalJSONTo

func (p *UserPreferences) MarshalJSONTo(enc *json.Encoder) error

func (UserPreferences) ModuleSpecifierPreferences

func (p UserPreferences) ModuleSpecifierPreferences() modulespecifiers.UserPreferences

func (UserPreferences) ParsedAutoImportFileExcludePatterns

func (p UserPreferences) ParsedAutoImportFileExcludePatterns(useCaseSensitiveFileNames bool) *vfsmatch.SpecMatcher

func (*UserPreferences) UnmarshalJSONFrom

func (p *UserPreferences) UnmarshalJSONFrom(dec *json.Decoder) error

func (UserPreferences) WithOverrides

func (p UserPreferences) WithOverrides(overrides UserPreferences) UserPreferences

WithOverrides returns a copy of p with non-zero fields from overrides applied on top. This is safe because all preference fields use types where zero = "not set": Tristate (TSUnknown=0), int (0), string (""), slice (nil).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL