From ecddfc4b7951aba6c8c611898eae15c7960c95d1 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Tue, 2 Dec 2025 12:40:34 -0800 Subject: [PATCH 1/5] format options implementation --- internal/execute/tsc.go | 3 +- internal/format/api.go | 11 +- internal/format/api_test.go | 13 +- internal/format/comment_test.go | 37 +- internal/format/context.go | 84 +---- internal/format/format_test.go | 7 +- internal/format/indent.go | 23 +- internal/format/rulecontext.go | 47 +-- internal/format/rules.go | 5 +- internal/format/span.go | 7 +- .../tests/autoImportCompletion_test.go | 4 +- internal/ls/change/tracker.go | 5 +- internal/ls/change/trackerimpl.go | 8 +- internal/ls/format.go | 17 +- internal/ls/format_test.go | 8 +- internal/ls/host.go | 3 +- internal/ls/languageservice.go | 5 +- internal/ls/lsutil/formatcodeoptions.go | 198 +++++++++++ internal/ls/lsutil/userpreferences.go | 321 +++++++++--------- internal/lsp/server.go | 44 +-- internal/project/configuration.go | 60 ++++ internal/project/session.go | 39 ++- internal/project/snapshot.go | 28 +- 23 files changed, 590 insertions(+), 387 deletions(-) create mode 100644 internal/ls/lsutil/formatcodeoptions.go create mode 100644 internal/project/configuration.go diff --git a/internal/execute/tsc.go b/internal/execute/tsc.go index 2ee2db6e9f..17f41e54d4 100644 --- a/internal/execute/tsc.go +++ b/internal/execute/tsc.go @@ -15,6 +15,7 @@ import ( "github.com/microsoft/typescript-go/internal/execute/tsc" "github.com/microsoft/typescript-go/internal/format" "github.com/microsoft/typescript-go/internal/jsonutil" + "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/parser" "github.com/microsoft/typescript-go/internal/pprof" "github.com/microsoft/typescript-go/internal/tsoptions" @@ -36,7 +37,7 @@ func CommandLine(sys tsc.System, commandLineArgs []string, testing tsc.CommandLi } func fmtMain(sys tsc.System, input, output string) tsc.ExitStatus { - ctx := format.WithFormatCodeSettings(context.Background(), format.GetDefaultFormatCodeSettings("\n"), "\n") + ctx := format.WithFormatCodeSettings(context.Background(), lsutil.GetDefaultFormatCodeSettings(), "\n") input = string(tspath.ToPath(input, sys.GetCurrentDirectory(), sys.FS().UseCaseSensitiveFileNames())) output = string(tspath.ToPath(output, sys.GetCurrentDirectory(), sys.FS().UseCaseSensitiveFileNames())) fileContent, ok := sys.FS().ReadFile(input) diff --git a/internal/format/api.go b/internal/format/api.go index 7acbd9208b..e5a69b7e20 100644 --- a/internal/format/api.go +++ b/internal/format/api.go @@ -6,6 +6,7 @@ import ( "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/core" + "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/scanner" "github.com/microsoft/typescript-go/internal/stringutil" ) @@ -28,16 +29,18 @@ const ( formatNewlineKey ) -func WithFormatCodeSettings(ctx context.Context, options *FormatCodeSettings, newLine string) context.Context { +func WithFormatCodeSettings(ctx context.Context, options *lsutil.FormatCodeSettings, newLine string) context.Context { ctx = context.WithValue(ctx, formatOptionsKey, options) ctx = context.WithValue(ctx, formatNewlineKey, newLine) // In strada, the rules map was both globally cached *and* cached into the context, for some reason. We skip that here and just use the global one. return ctx } -func GetFormatCodeSettingsFromContext(ctx context.Context) *FormatCodeSettings { - opt := ctx.Value(formatOptionsKey).(*FormatCodeSettings) - return opt +func GetFormatCodeSettingsFromContext(ctx context.Context) *lsutil.FormatCodeSettings { + if opt := ctx.Value(formatOptionsKey); opt != nil { + return opt.(*lsutil.FormatCodeSettings) + } + return nil } func GetNewLineOrDefaultFromContext(ctx context.Context) string { // TODO: Move into broader LS - more than just the formatter uses the newline editor setting/host new line diff --git a/internal/format/api_test.go b/internal/format/api_test.go index 048d816f58..ecf45c5dd4 100644 --- a/internal/format/api_test.go +++ b/internal/format/api_test.go @@ -9,6 +9,7 @@ import ( "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/format" + "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/parser" "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/repo" @@ -38,14 +39,14 @@ func TestFormat(t *testing.T) { t.Run("format checker.ts", func(t *testing.T) { t.Parallel() - ctx := format.WithFormatCodeSettings(t.Context(), &format.FormatCodeSettings{ - EditorSettings: format.EditorSettings{ + ctx := format.WithFormatCodeSettings(t.Context(), &lsutil.FormatCodeSettings{ + EditorSettings: lsutil.EditorSettings{ TabSize: 4, IndentSize: 4, BaseIndentSize: 4, NewLineCharacter: "\n", ConvertTabsToSpaces: true, - IndentStyle: format.IndentStyleSmart, + IndentStyle: lsutil.IndentStyleSmart, TrimTrailingWhitespace: true, }, InsertSpaceBeforeTypeAnnotation: core.TSTrue, @@ -67,14 +68,14 @@ func TestFormat(t *testing.T) { } func BenchmarkFormat(b *testing.B) { - ctx := format.WithFormatCodeSettings(b.Context(), &format.FormatCodeSettings{ - EditorSettings: format.EditorSettings{ + ctx := format.WithFormatCodeSettings(b.Context(), &lsutil.FormatCodeSettings{ + EditorSettings: lsutil.EditorSettings{ TabSize: 4, IndentSize: 4, BaseIndentSize: 4, NewLineCharacter: "\n", ConvertTabsToSpaces: true, - IndentStyle: format.IndentStyleSmart, + IndentStyle: lsutil.IndentStyleSmart, TrimTrailingWhitespace: true, }, InsertSpaceBeforeTypeAnnotation: core.TSTrue, diff --git a/internal/format/comment_test.go b/internal/format/comment_test.go index f94799d82d..c33fc04355 100644 --- a/internal/format/comment_test.go +++ b/internal/format/comment_test.go @@ -7,6 +7,7 @@ import ( "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/format" + "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/parser" "gotest.tools/v3/assert" ) @@ -16,14 +17,14 @@ func TestCommentFormatting(t *testing.T) { t.Run("format comment issue reproduction", func(t *testing.T) { t.Parallel() - ctx := format.WithFormatCodeSettings(t.Context(), &format.FormatCodeSettings{ - EditorSettings: format.EditorSettings{ + ctx := format.WithFormatCodeSettings(t.Context(), &lsutil.FormatCodeSettings{ + EditorSettings: lsutil.EditorSettings{ TabSize: 4, IndentSize: 4, BaseIndentSize: 4, NewLineCharacter: "\n", ConvertTabsToSpaces: true, - IndentStyle: format.IndentStyleSmart, + IndentStyle: lsutil.IndentStyleSmart, TrimTrailingWhitespace: true, }, InsertSpaceBeforeTypeAnnotation: core.TSTrue, @@ -67,14 +68,14 @@ func TestCommentFormatting(t *testing.T) { t.Run("format JSDoc with tab indentation", func(t *testing.T) { t.Parallel() - ctx := format.WithFormatCodeSettings(t.Context(), &format.FormatCodeSettings{ - EditorSettings: format.EditorSettings{ + ctx := format.WithFormatCodeSettings(t.Context(), &lsutil.FormatCodeSettings{ + EditorSettings: lsutil.EditorSettings{ TabSize: 4, IndentSize: 4, BaseIndentSize: 0, NewLineCharacter: "\n", ConvertTabsToSpaces: false, // Use tabs - IndentStyle: format.IndentStyleSmart, + IndentStyle: lsutil.IndentStyleSmart, TrimTrailingWhitespace: true, }, InsertSpaceBeforeTypeAnnotation: core.TSTrue, @@ -104,14 +105,14 @@ func TestCommentFormatting(t *testing.T) { t.Run("format comment inside multi-line argument list", func(t *testing.T) { t.Parallel() - ctx := format.WithFormatCodeSettings(t.Context(), &format.FormatCodeSettings{ - EditorSettings: format.EditorSettings{ + ctx := format.WithFormatCodeSettings(t.Context(), &lsutil.FormatCodeSettings{ + EditorSettings: lsutil.EditorSettings{ TabSize: 4, IndentSize: 4, BaseIndentSize: 0, NewLineCharacter: "\n", ConvertTabsToSpaces: false, // Use tabs - IndentStyle: format.IndentStyleSmart, + IndentStyle: lsutil.IndentStyleSmart, TrimTrailingWhitespace: true, }, InsertSpaceBeforeTypeAnnotation: core.TSTrue, @@ -137,14 +138,14 @@ func TestCommentFormatting(t *testing.T) { t.Run("format comment in chained method calls", func(t *testing.T) { t.Parallel() - ctx := format.WithFormatCodeSettings(t.Context(), &format.FormatCodeSettings{ - EditorSettings: format.EditorSettings{ + ctx := format.WithFormatCodeSettings(t.Context(), &lsutil.FormatCodeSettings{ + EditorSettings: lsutil.EditorSettings{ TabSize: 4, IndentSize: 4, BaseIndentSize: 0, NewLineCharacter: "\n", ConvertTabsToSpaces: false, // Use tabs - IndentStyle: format.IndentStyleSmart, + IndentStyle: lsutil.IndentStyleSmart, TrimTrailingWhitespace: true, }, InsertSpaceBeforeTypeAnnotation: core.TSTrue, @@ -171,14 +172,14 @@ func TestCommentFormatting(t *testing.T) { // Regression test for issue #1928 - panic when formatting chained method call with comment t.Run("format chained method call with comment (issue #1928)", func(t *testing.T) { t.Parallel() - ctx := format.WithFormatCodeSettings(t.Context(), &format.FormatCodeSettings{ - EditorSettings: format.EditorSettings{ + ctx := format.WithFormatCodeSettings(t.Context(), &lsutil.FormatCodeSettings{ + EditorSettings: lsutil.EditorSettings{ TabSize: 4, IndentSize: 4, BaseIndentSize: 0, NewLineCharacter: "\n", ConvertTabsToSpaces: false, // Use tabs - IndentStyle: format.IndentStyleSmart, + IndentStyle: lsutil.IndentStyleSmart, TrimTrailingWhitespace: true, }, InsertSpaceBeforeTypeAnnotation: core.TSTrue, @@ -208,14 +209,14 @@ func TestSliceBoundsPanic(t *testing.T) { t.Run("format code with trailing semicolon should not panic", func(t *testing.T) { t.Parallel() - ctx := format.WithFormatCodeSettings(t.Context(), &format.FormatCodeSettings{ - EditorSettings: format.EditorSettings{ + ctx := format.WithFormatCodeSettings(t.Context(), &lsutil.FormatCodeSettings{ + EditorSettings: lsutil.EditorSettings{ TabSize: 4, IndentSize: 4, BaseIndentSize: 4, NewLineCharacter: "\n", ConvertTabsToSpaces: true, - IndentStyle: format.IndentStyleSmart, + IndentStyle: lsutil.IndentStyleSmart, TrimTrailingWhitespace: true, }, InsertSpaceBeforeTypeAnnotation: core.TSTrue, diff --git a/internal/format/context.go b/internal/format/context.go index bb059e45a4..fa17598815 100644 --- a/internal/format/context.go +++ b/internal/format/context.go @@ -3,88 +3,10 @@ package format import ( "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/core" + "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/scanner" ) -type IndentStyle int - -const ( - IndentStyleNone IndentStyle = iota - IndentStyleBlock - IndentStyleSmart -) - -type SemicolonPreference string - -const ( - SemicolonPreferenceIgnore SemicolonPreference = "ignore" - SemicolonPreferenceInsert SemicolonPreference = "insert" - SemicolonPreferenceRemove SemicolonPreference = "remove" -) - -type EditorSettings struct { - BaseIndentSize int - IndentSize int - TabSize int - NewLineCharacter string - ConvertTabsToSpaces bool - IndentStyle IndentStyle - TrimTrailingWhitespace bool -} - -type FormatCodeSettings struct { - EditorSettings - InsertSpaceAfterCommaDelimiter core.Tristate - InsertSpaceAfterSemicolonInForStatements core.Tristate - InsertSpaceBeforeAndAfterBinaryOperators core.Tristate - InsertSpaceAfterConstructor core.Tristate - InsertSpaceAfterKeywordsInControlFlowStatements core.Tristate - InsertSpaceAfterFunctionKeywordForAnonymousFunctions core.Tristate - InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis core.Tristate - InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets core.Tristate - InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces core.Tristate - InsertSpaceAfterOpeningAndBeforeClosingEmptyBraces core.Tristate - InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces core.Tristate - InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces core.Tristate - InsertSpaceAfterTypeAssertion core.Tristate - InsertSpaceBeforeFunctionParenthesis core.Tristate - PlaceOpenBraceOnNewLineForFunctions core.Tristate - PlaceOpenBraceOnNewLineForControlBlocks core.Tristate - InsertSpaceBeforeTypeAnnotation core.Tristate - IndentMultiLineObjectLiteralBeginningOnBlankLine core.Tristate - Semicolons SemicolonPreference - IndentSwitchCase core.Tristate -} - -func GetDefaultFormatCodeSettings(newLineCharacter string) *FormatCodeSettings { - return &FormatCodeSettings{ - EditorSettings: EditorSettings{ - IndentSize: 4, - TabSize: 4, - NewLineCharacter: newLineCharacter, - ConvertTabsToSpaces: true, - IndentStyle: IndentStyleSmart, - TrimTrailingWhitespace: true, - }, - InsertSpaceAfterConstructor: core.TSFalse, - InsertSpaceAfterCommaDelimiter: core.TSTrue, - InsertSpaceAfterSemicolonInForStatements: core.TSTrue, - InsertSpaceBeforeAndAfterBinaryOperators: core.TSTrue, - InsertSpaceAfterKeywordsInControlFlowStatements: core.TSTrue, - InsertSpaceAfterFunctionKeywordForAnonymousFunctions: core.TSFalse, - InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: core.TSFalse, - InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: core.TSFalse, - InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: core.TSTrue, - InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: core.TSFalse, - InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: core.TSFalse, - InsertSpaceBeforeFunctionParenthesis: core.TSFalse, - PlaceOpenBraceOnNewLineForFunctions: core.TSFalse, - PlaceOpenBraceOnNewLineForControlBlocks: core.TSFalse, - Semicolons: SemicolonPreferenceIgnore, - IndentSwitchCase: core.TSTrue, - } -} - type FormattingContext struct { currentTokenSpan TextRangeWithKind nextTokenSpan TextRangeWithKind @@ -100,12 +22,12 @@ type FormattingContext struct { SourceFile *ast.SourceFile FormattingRequestKind FormatRequestKind - Options *FormatCodeSettings + Options *lsutil.FormatCodeSettings scanner *scanner.Scanner } -func NewFormattingContext(file *ast.SourceFile, kind FormatRequestKind, options *FormatCodeSettings) *FormattingContext { +func NewFormattingContext(file *ast.SourceFile, kind FormatRequestKind, options *lsutil.FormatCodeSettings) *FormattingContext { res := &FormattingContext{ SourceFile: file, FormattingRequestKind: kind, diff --git a/internal/format/format_test.go b/internal/format/format_test.go index 1bf7945076..8bbce3e503 100644 --- a/internal/format/format_test.go +++ b/internal/format/format_test.go @@ -7,6 +7,7 @@ import ( "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/format" + "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/parser" "gotest.tools/v3/assert" ) @@ -30,14 +31,14 @@ func TestFormatNoTrailingNewline(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { t.Parallel() - ctx := format.WithFormatCodeSettings(t.Context(), &format.FormatCodeSettings{ - EditorSettings: format.EditorSettings{ + ctx := format.WithFormatCodeSettings(t.Context(), &lsutil.FormatCodeSettings{ + EditorSettings: lsutil.EditorSettings{ TabSize: 4, IndentSize: 4, BaseIndentSize: 4, NewLineCharacter: "\n", ConvertTabsToSpaces: true, - IndentStyle: format.IndentStyleSmart, + IndentStyle: lsutil.IndentStyleSmart, TrimTrailingWhitespace: true, }, }, "\n") diff --git a/internal/format/indent.go b/internal/format/indent.go index d5ccb949a3..7aff7e4921 100644 --- a/internal/format/indent.go +++ b/internal/format/indent.go @@ -8,11 +8,12 @@ import ( "github.com/microsoft/typescript-go/internal/astnav" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/debug" + "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/scanner" "github.com/microsoft/typescript-go/internal/stringutil" ) -func GetIndentationForNode(n *ast.Node, ignoreActualIndentationRange *core.TextRange, sourceFile *ast.SourceFile, options *FormatCodeSettings) int { +func GetIndentationForNode(n *ast.Node, ignoreActualIndentationRange *core.TextRange, sourceFile *ast.SourceFile, options *lsutil.FormatCodeSettings) int { startline, startpos := scanner.GetECMALineAndCharacterOfPosition(sourceFile, scanner.GetTokenPosOfNode(n, sourceFile, false)) return getIndentationForNodeWorker(n, startline, startpos, ignoreActualIndentationRange /*indentationDelta*/, 0, sourceFile /*isNextChild*/, false, options) } @@ -25,7 +26,7 @@ func getIndentationForNodeWorker( indentationDelta int, sourceFile *ast.SourceFile, isNextChild bool, - options *FormatCodeSettings, + options *lsutil.FormatCodeSettings, ) int { parent := current.Parent @@ -116,7 +117,7 @@ func getIndentationForNodeWorker( /* * Function returns -1 if actual indentation for node should not be used (i.e because node is nested expression) */ -func getActualIndentationForNode(current *ast.Node, parent *ast.Node, cuurentLine int, currentChar int, parentAndChildShareLine bool, sourceFile *ast.SourceFile, options *FormatCodeSettings) int { +func getActualIndentationForNode(current *ast.Node, parent *ast.Node, cuurentLine int, currentChar int, parentAndChildShareLine bool, sourceFile *ast.SourceFile, options *lsutil.FormatCodeSettings) int { // actual indentation is used for statements\declarations if one of cases below is true: // - parent is SourceFile - by default immediate children of SourceFile are not indented except when user indents them manually // - parent and child are not on the same line @@ -138,7 +139,7 @@ func isArgumentAndStartLineOverlapsExpressionBeingCalled(parent *ast.Node, child return expressionOfCallExpressionEndLine == childStartLine } -func getActualIndentationForListItem(node *ast.Node, sourceFile *ast.SourceFile, options *FormatCodeSettings, listIndentsChild bool) int { +func getActualIndentationForListItem(node *ast.Node, sourceFile *ast.SourceFile, options *lsutil.FormatCodeSettings, listIndentsChild bool) int { if node.Parent != nil && node.Parent.Kind == ast.KindVariableDeclarationList { // VariableDeclarationList has no wrapping tokens return -1 @@ -165,7 +166,7 @@ func getActualIndentationForListItem(node *ast.Node, sourceFile *ast.SourceFile, return -1 } -func getActualIndentationForListStartLine(list *ast.NodeList, sourceFile *ast.SourceFile, options *FormatCodeSettings) int { +func getActualIndentationForListStartLine(list *ast.NodeList, sourceFile *ast.SourceFile, options *lsutil.FormatCodeSettings) int { if list == nil { return -1 } @@ -173,7 +174,7 @@ func getActualIndentationForListStartLine(list *ast.NodeList, sourceFile *ast.So return findColumnForFirstNonWhitespaceCharacterInLine(line, char, sourceFile, options) } -func deriveActualIndentationFromList(list *ast.NodeList, index int, sourceFile *ast.SourceFile, options *FormatCodeSettings) int { +func deriveActualIndentationFromList(list *ast.NodeList, index int, sourceFile *ast.SourceFile, options *lsutil.FormatCodeSettings) int { debug.Assert(list != nil && index >= 0 && index < len(list.Nodes)) node := list.Nodes[index] @@ -198,12 +199,12 @@ func deriveActualIndentationFromList(list *ast.NodeList, index int, sourceFile * return -1 } -func findColumnForFirstNonWhitespaceCharacterInLine(line int, char int, sourceFile *ast.SourceFile, options *FormatCodeSettings) int { +func findColumnForFirstNonWhitespaceCharacterInLine(line int, char int, sourceFile *ast.SourceFile, options *lsutil.FormatCodeSettings) int { lineStart := scanner.GetECMAPositionOfLineAndCharacter(sourceFile, line, 0) return FindFirstNonWhitespaceColumn(lineStart, lineStart+char, sourceFile, options) } -func FindFirstNonWhitespaceColumn(startPos int, endPos int, sourceFile *ast.SourceFile, options *FormatCodeSettings) int { +func FindFirstNonWhitespaceColumn(startPos int, endPos int, sourceFile *ast.SourceFile, options *lsutil.FormatCodeSettings) int { _, col := findFirstNonWhitespaceCharacterAndColumn(startPos, endPos, sourceFile, options) return col } @@ -215,7 +216,7 @@ func FindFirstNonWhitespaceColumn(startPos int, endPos int, sourceFile *ast.Sour * value of 'character' for '$' is 3 * value of 'column' for '$' is 6 (assuming that tab size is 4) */ -func findFirstNonWhitespaceCharacterAndColumn(startPos int, endPos int, sourceFile *ast.SourceFile, options *FormatCodeSettings) (character int, column int) { +func findFirstNonWhitespaceCharacterAndColumn(startPos int, endPos int, sourceFile *ast.SourceFile, options *lsutil.FormatCodeSettings) (character int, column int) { character = 0 column = 0 text := sourceFile.Text() @@ -375,7 +376,7 @@ func isControlFlowEndingStatement(kind ast.Kind, parentKind ast.Kind) bool { * True when the parent node should indent the given child by an explicit rule. * @param isNextChild If true, we are judging indent of a hypothetical child *after* this one, not the current child. */ -func ShouldIndentChildNode(settings *FormatCodeSettings, parent *ast.Node, child *ast.Node, sourceFile *ast.SourceFile, isNextChildArg ...bool) bool { +func ShouldIndentChildNode(settings *lsutil.FormatCodeSettings, parent *ast.Node, child *ast.Node, sourceFile *ast.SourceFile, isNextChildArg ...bool) bool { isNextChild := false if len(isNextChildArg) > 0 { isNextChild = isNextChildArg[0] @@ -384,7 +385,7 @@ func ShouldIndentChildNode(settings *FormatCodeSettings, parent *ast.Node, child return NodeWillIndentChild(settings, parent, child, sourceFile, false) && !(isNextChild && child != nil && isControlFlowEndingStatement(child.Kind, parent.Kind)) } -func NodeWillIndentChild(settings *FormatCodeSettings, parent *ast.Node, child *ast.Node, sourceFile *ast.SourceFile, indentByDefault bool) bool { +func NodeWillIndentChild(settings *lsutil.FormatCodeSettings, parent *ast.Node, child *ast.Node, sourceFile *ast.SourceFile, indentByDefault bool) bool { childKind := ast.KindUnknown if child != nil { childKind = child.Kind diff --git a/internal/format/rulecontext.go b/internal/format/rulecontext.go index ca276c3976..de7a150f8b 100644 --- a/internal/format/rulecontext.go +++ b/internal/format/rulecontext.go @@ -15,84 +15,87 @@ import ( /// type ( - optionSelector = func(options *FormatCodeSettings) core.Tristate - anyOptionSelector[T comparable] = func(options *FormatCodeSettings) T + optionSelector = func(options *lsutil.FormatCodeSettings) core.Tristate + anyOptionSelector[T comparable] = func(options *lsutil.FormatCodeSettings) T ) -func semicolonOption(options *FormatCodeSettings) SemicolonPreference { return options.Semicolons } -func insertSpaceAfterCommaDelimiterOption(options *FormatCodeSettings) core.Tristate { +func semicolonOption(options *lsutil.FormatCodeSettings) lsutil.SemicolonPreference { + return options.Semicolons +} + +func insertSpaceAfterCommaDelimiterOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceAfterCommaDelimiter } -func insertSpaceAfterSemicolonInForStatementsOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceAfterSemicolonInForStatementsOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceAfterSemicolonInForStatements } -func insertSpaceBeforeAndAfterBinaryOperatorsOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceBeforeAndAfterBinaryOperatorsOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceBeforeAndAfterBinaryOperators } -func insertSpaceAfterConstructorOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceAfterConstructorOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceAfterConstructor } -func insertSpaceAfterKeywordsInControlFlowStatementsOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceAfterKeywordsInControlFlowStatementsOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceAfterKeywordsInControlFlowStatements } -func insertSpaceAfterFunctionKeywordForAnonymousFunctionsOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceAfterFunctionKeywordForAnonymousFunctionsOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceAfterFunctionKeywordForAnonymousFunctions } -func insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesisOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesisOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis } -func insertSpaceAfterOpeningAndBeforeClosingNonemptyBracketsOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceAfterOpeningAndBeforeClosingNonemptyBracketsOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets } -func insertSpaceAfterOpeningAndBeforeClosingNonemptyBracesOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceAfterOpeningAndBeforeClosingNonemptyBracesOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces } -func insertSpaceAfterOpeningAndBeforeClosingEmptyBracesOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceAfterOpeningAndBeforeClosingEmptyBracesOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceAfterOpeningAndBeforeClosingEmptyBraces } -func insertSpaceAfterOpeningAndBeforeClosingTemplateStringBracesOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceAfterOpeningAndBeforeClosingTemplateStringBracesOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces } -func insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBracesOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBracesOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces } -func insertSpaceAfterTypeAssertionOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceAfterTypeAssertionOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceAfterTypeAssertion } -func insertSpaceBeforeFunctionParenthesisOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceBeforeFunctionParenthesisOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceBeforeFunctionParenthesis } -func placeOpenBraceOnNewLineForFunctionsOption(options *FormatCodeSettings) core.Tristate { +func placeOpenBraceOnNewLineForFunctionsOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.PlaceOpenBraceOnNewLineForFunctions } -func placeOpenBraceOnNewLineForControlBlocksOption(options *FormatCodeSettings) core.Tristate { +func placeOpenBraceOnNewLineForControlBlocksOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.PlaceOpenBraceOnNewLineForControlBlocks } -func insertSpaceBeforeTypeAnnotationOption(options *FormatCodeSettings) core.Tristate { +func insertSpaceBeforeTypeAnnotationOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.InsertSpaceBeforeTypeAnnotation } -func indentMultiLineObjectLiteralBeginningOnBlankLineOption(options *FormatCodeSettings) core.Tristate { +func indentMultiLineObjectLiteralBeginningOnBlankLineOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.IndentMultiLineObjectLiteralBeginningOnBlankLine } -func indentSwitchCaseOption(options *FormatCodeSettings) core.Tristate { +func indentSwitchCaseOption(options *lsutil.FormatCodeSettings) core.Tristate { return options.IndentSwitchCase } diff --git a/internal/format/rules.go b/internal/format/rules.go index 07af86ef99..2d80fea624 100644 --- a/internal/format/rules.go +++ b/internal/format/rules.go @@ -4,6 +4,7 @@ import ( "slices" "github.com/microsoft/typescript-go/internal/ast" + "github.com/microsoft/typescript-go/internal/ls/lsutil" ) func getAllRules() []ruleSpec { @@ -377,8 +378,8 @@ func getAllRules() []ruleSpec { rule("SpaceBeforeTypeAnnotation", anyToken, []ast.Kind{ast.KindQuestionToken, ast.KindColonToken}, []contextPredicate{isOptionEnabled(insertSpaceBeforeTypeAnnotationOption), isNonJsxSameLineTokenContext, isTypeAnnotationContext}, ruleActionInsertSpace), rule("NoSpaceBeforeTypeAnnotation", anyToken, []ast.Kind{ast.KindQuestionToken, ast.KindColonToken}, []contextPredicate{isOptionDisabledOrUndefined(insertSpaceBeforeTypeAnnotationOption), isNonJsxSameLineTokenContext, isTypeAnnotationContext}, ruleActionDeleteSpace), - rule("NoOptionalSemicolon", ast.KindSemicolonToken, anyTokenIncludingEOF, []contextPredicate{optionEquals(semicolonOption, SemicolonPreferenceRemove), isSemicolonDeletionContext}, ruleActionDeleteToken), - rule("OptionalSemicolon", anyToken, anyTokenIncludingEOF, []contextPredicate{optionEquals(semicolonOption, SemicolonPreferenceInsert), isSemicolonInsertionContext}, ruleActionInsertTrailingSemicolon), + rule("NoOptionalSemicolon", ast.KindSemicolonToken, anyTokenIncludingEOF, []contextPredicate{optionEquals(semicolonOption, lsutil.SemicolonPreferenceRemove), isSemicolonDeletionContext}, ruleActionDeleteToken), + rule("OptionalSemicolon", anyToken, anyTokenIncludingEOF, []contextPredicate{optionEquals(semicolonOption, lsutil.SemicolonPreferenceInsert), isSemicolonInsertionContext}, ruleActionInsertTrailingSemicolon), } // These rules are lower in priority than user-configurable. Rules earlier in this list have priority over rules later in the list. diff --git a/internal/format/span.go b/internal/format/span.go index f8d73d40b6..018077f770 100644 --- a/internal/format/span.go +++ b/internal/format/span.go @@ -11,6 +11,7 @@ import ( "github.com/microsoft/typescript-go/internal/astnav" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/debug" + "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/scanner" "github.com/microsoft/typescript-go/internal/stringutil" ) @@ -81,7 +82,7 @@ func getScanStartPosition(enclosingNode *ast.Node, originalRange core.TextRange, * if parent is on the different line - its delta was already contributed * to the initial indentation. */ -func getOwnOrInheritedDelta(n *ast.Node, options *FormatCodeSettings, sourceFile *ast.SourceFile) int { +func getOwnOrInheritedDelta(n *ast.Node, options *lsutil.FormatCodeSettings, sourceFile *ast.SourceFile) int { previousLine := -1 var child *ast.Node for n != nil { @@ -968,7 +969,7 @@ func (w *formatSpanWorker) indentMultilineComment(commentRange core.TextRange, i } } -func getIndentationString(indentation int, options *FormatCodeSettings) string { +func getIndentationString(indentation int, options *lsutil.FormatCodeSettings) string { // go's `strings.Repeat` already has static, global caching for repeated tabs and spaces, so there's no need to cache here like in strada if !options.ConvertTabsToSpaces { tabs := int(math.Floor(float64(indentation) / float64(options.TabSize))) @@ -1080,7 +1081,7 @@ type dynamicIndenter struct { indentation int delta int - options *FormatCodeSettings + options *lsutil.FormatCodeSettings sourceFile *ast.SourceFile } diff --git a/internal/fourslash/tests/autoImportCompletion_test.go b/internal/fourslash/tests/autoImportCompletion_test.go index fb107e2d6a..8da184c46f 100644 --- a/internal/fourslash/tests/autoImportCompletion_test.go +++ b/internal/fourslash/tests/autoImportCompletion_test.go @@ -43,8 +43,8 @@ a/**/ f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ UserPreferences: &lsutil.UserPreferences{ // completion autoimport preferences off; this tests if fourslash server communication correctly registers changes in user preferences - IncludeCompletionsForModuleExports: core.TSUnknown, - IncludeCompletionsForImportStatements: core.TSUnknown, + IncludeCompletionsForModuleExports: core.TSFalse, + IncludeCompletionsForImportStatements: core.TSFalse, }, IsIncomplete: false, ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ diff --git a/internal/ls/change/tracker.go b/internal/ls/change/tracker.go index 28c5c65205..7490decfa6 100644 --- a/internal/ls/change/tracker.go +++ b/internal/ls/change/tracker.go @@ -10,6 +10,7 @@ import ( "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/format" "github.com/microsoft/typescript-go/internal/ls/lsconv" + "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/lsp/lsproto" "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/scanner" @@ -75,7 +76,7 @@ type trackerEdit struct { type Tracker struct { // initialized with - formatSettings *format.FormatCodeSettings + formatSettings *lsutil.FormatCodeSettings newLine string converters *lsconv.Converters ctx context.Context @@ -95,7 +96,7 @@ type deletedNode struct { node *ast.Node } -func NewTracker(ctx context.Context, compilerOptions *core.CompilerOptions, formatOptions *format.FormatCodeSettings, converters *lsconv.Converters) *Tracker { +func NewTracker(ctx context.Context, compilerOptions *core.CompilerOptions, formatOptions *lsutil.FormatCodeSettings, converters *lsconv.Converters) *Tracker { emitContext := printer.NewEmitContext() newLine := compilerOptions.NewLine.GetNewLineCharacter() ctx = format.WithFormatCodeSettings(ctx, formatOptions, newLine) // !!! formatSettings in context? diff --git a/internal/ls/change/trackerimpl.go b/internal/ls/change/trackerimpl.go index d39c5422c8..8c982750b6 100644 --- a/internal/ls/change/trackerimpl.go +++ b/internal/ls/change/trackerimpl.go @@ -112,11 +112,11 @@ func (t *Tracker) getFormattedTextOfNode(nodeIn *ast.Node, targetSourceFile *ast return core.ApplyBulkEdits(text, changes) } -func getFormatCodeSettingsForWriting(options *format.FormatCodeSettings, sourceFile *ast.SourceFile) *format.FormatCodeSettings { - shouldAutoDetectSemicolonPreference := options.Semicolons == format.SemicolonPreferenceIgnore - shouldRemoveSemicolons := options.Semicolons == format.SemicolonPreferenceRemove || shouldAutoDetectSemicolonPreference && !lsutil.ProbablyUsesSemicolons(sourceFile) +func getFormatCodeSettingsForWriting(options *lsutil.FormatCodeSettings, sourceFile *ast.SourceFile) *lsutil.FormatCodeSettings { + shouldAutoDetectSemicolonPreference := options.Semicolons == lsutil.SemicolonPreferenceIgnore + shouldRemoveSemicolons := options.Semicolons == lsutil.SemicolonPreferenceRemove || shouldAutoDetectSemicolonPreference && !lsutil.ProbablyUsesSemicolons(sourceFile) if shouldRemoveSemicolons { - options.Semicolons = format.SemicolonPreferenceRemove + options.Semicolons = lsutil.SemicolonPreferenceRemove } return options diff --git a/internal/ls/format.go b/internal/ls/format.go index 9e0f55cf19..0b14f57e33 100644 --- a/internal/ls/format.go +++ b/internal/ls/format.go @@ -8,12 +8,13 @@ import ( "github.com/microsoft/typescript-go/internal/astnav" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/format" + "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/lsp/lsproto" "github.com/microsoft/typescript-go/internal/scanner" ) -func toFormatCodeSettings(opt *lsproto.FormattingOptions, newLine string) *format.FormatCodeSettings { - initial := format.GetDefaultFormatCodeSettings(newLine) +func toFormatCodeSettings(opt *lsproto.FormattingOptions) *lsutil.FormatCodeSettings { + initial := lsutil.GetDefaultFormatCodeSettings() initial.TabSize = int(opt.TabSize) initial.IndentSize = int(opt.TabSize) initial.ConvertTabsToSpaces = opt.InsertSpaces @@ -46,7 +47,7 @@ func (l *LanguageService) ProvideFormatDocument( edits := l.toLSProtoTextEdits(file, l.getFormattingEditsForDocument( ctx, file, - toFormatCodeSettings(options, l.GetProgram().Options().NewLine.GetNewLineCharacter()), + toFormatCodeSettings(options), )) return lsproto.TextEditsOrNull{TextEdits: &edits}, nil } @@ -61,7 +62,7 @@ func (l *LanguageService) ProvideFormatDocumentRange( edits := l.toLSProtoTextEdits(file, l.getFormattingEditsForRange( ctx, file, - toFormatCodeSettings(options, l.GetProgram().Options().NewLine.GetNewLineCharacter()), + toFormatCodeSettings(options), l.converters.FromLSPRange(file, r), )) return lsproto.TextEditsOrNull{TextEdits: &edits}, nil @@ -78,7 +79,7 @@ func (l *LanguageService) ProvideFormatDocumentOnType( edits := l.toLSProtoTextEdits(file, l.getFormattingEditsAfterKeystroke( ctx, file, - toFormatCodeSettings(options, l.GetProgram().Options().NewLine.GetNewLineCharacter()), + toFormatCodeSettings(options), int(l.converters.LineAndCharacterToPosition(file, position)), character, )) @@ -88,7 +89,7 @@ func (l *LanguageService) ProvideFormatDocumentOnType( func (l *LanguageService) getFormattingEditsForRange( ctx context.Context, file *ast.SourceFile, - options *format.FormatCodeSettings, + options *lsutil.FormatCodeSettings, r core.TextRange, ) []core.TextChange { ctx = format.WithFormatCodeSettings(ctx, options, options.NewLineCharacter) @@ -98,7 +99,7 @@ func (l *LanguageService) getFormattingEditsForRange( func (l *LanguageService) getFormattingEditsForDocument( ctx context.Context, file *ast.SourceFile, - options *format.FormatCodeSettings, + options *lsutil.FormatCodeSettings, ) []core.TextChange { ctx = format.WithFormatCodeSettings(ctx, options, options.NewLineCharacter) return format.FormatDocument(ctx, file) @@ -107,7 +108,7 @@ func (l *LanguageService) getFormattingEditsForDocument( func (l *LanguageService) getFormattingEditsAfterKeystroke( ctx context.Context, file *ast.SourceFile, - options *format.FormatCodeSettings, + options *lsutil.FormatCodeSettings, position int, key string, ) []core.TextChange { diff --git a/internal/ls/format_test.go b/internal/ls/format_test.go index 8d84bcb211..ed2a1fddf3 100644 --- a/internal/ls/format_test.go +++ b/internal/ls/format_test.go @@ -6,7 +6,7 @@ import ( "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/core" - "github.com/microsoft/typescript-go/internal/format" + "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/parser" ) @@ -26,7 +26,7 @@ func TestGetFormattingEditsAfterKeystroke_EmptyFile(t *testing.T) { // Test formatting after keystroke with newline character at position 0 ctx := context.Background() - options := format.GetDefaultFormatCodeSettings("\n") + options := lsutil.GetDefaultFormatCodeSettings() // This should not panic edits := langService.getFormattingEditsAfterKeystroke( @@ -56,7 +56,7 @@ func TestGetFormattingEditsAfterKeystroke_SimpleStatement(t *testing.T) { // Test formatting after keystroke with newline character at end of statement ctx := context.Background() - options := format.GetDefaultFormatCodeSettings("\n") + options := lsutil.GetDefaultFormatCodeSettings() // This should not panic edits := langService.getFormattingEditsAfterKeystroke( @@ -118,7 +118,7 @@ func TestGetFormattingEditsForRange_FunctionBody(t *testing.T) { langService := &LanguageService{} ctx := context.Background() - options := format.GetDefaultFormatCodeSettings("\n") + options := lsutil.GetDefaultFormatCodeSettings() // This should not panic edits := langService.getFormattingEditsForRange( diff --git a/internal/ls/host.go b/internal/ls/host.go index 8f517b787c..d6982566aa 100644 --- a/internal/ls/host.go +++ b/internal/ls/host.go @@ -1,7 +1,6 @@ package ls import ( - "github.com/microsoft/typescript-go/internal/format" "github.com/microsoft/typescript-go/internal/ls/lsconv" "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/sourcemap" @@ -12,6 +11,6 @@ type Host interface { ReadFile(path string) (contents string, ok bool) Converters() *lsconv.Converters UserPreferences() *lsutil.UserPreferences - FormatOptions() *format.FormatCodeSettings + FormatOptions() *lsutil.FormatCodeSettings GetECMALineInfo(fileName string) *sourcemap.ECMALineInfo } diff --git a/internal/ls/languageservice.go b/internal/ls/languageservice.go index e2fc95f24c..1064f41a0e 100644 --- a/internal/ls/languageservice.go +++ b/internal/ls/languageservice.go @@ -3,7 +3,6 @@ package ls import ( "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/compiler" - "github.com/microsoft/typescript-go/internal/format" "github.com/microsoft/typescript-go/internal/ls/lsconv" "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/lsp/lsproto" @@ -37,11 +36,11 @@ func (l *LanguageService) UserPreferences() *lsutil.UserPreferences { return l.host.UserPreferences() } -func (l *LanguageService) FormatOptions() *format.FormatCodeSettings { +func (l *LanguageService) FormatOptions() *lsutil.FormatCodeSettings { if formatOptions := l.host.FormatOptions(); formatOptions != nil { return formatOptions } - return format.GetDefaultFormatCodeSettings(l.GetProgram().Options().NewLine.GetNewLineCharacter()) + return lsutil.GetDefaultFormatCodeSettings() } func (l *LanguageService) tryGetProgramAndFile(fileName string) (*compiler.Program, *ast.SourceFile) { diff --git a/internal/ls/lsutil/formatcodeoptions.go b/internal/ls/lsutil/formatcodeoptions.go new file mode 100644 index 0000000000..cd7994f087 --- /dev/null +++ b/internal/ls/lsutil/formatcodeoptions.go @@ -0,0 +1,198 @@ +package lsutil + +import ( + "strings" + + "github.com/microsoft/typescript-go/internal/core" + "github.com/microsoft/typescript-go/internal/tsoptions" +) + +type IndentStyle int + +const ( + IndentStyleNone IndentStyle = iota + IndentStyleBlock + IndentStyleSmart +) + +func parseIndentStyle(v any) IndentStyle { + switch s := v.(type) { + case string: + switch strings.ToLower(s) { + case "none": + return IndentStyleNone + case "block": + return IndentStyleBlock + case "smart": + return IndentStyleSmart + } + } + return IndentStyleSmart +} + +type SemicolonPreference string + +const ( + SemicolonPreferenceIgnore SemicolonPreference = "ignore" + SemicolonPreferenceInsert SemicolonPreference = "insert" + SemicolonPreferenceRemove SemicolonPreference = "remove" +) + +func parseSemicolonPreference(v any) SemicolonPreference { + if s, ok := v.(string); ok { + switch strings.ToLower(s) { + case "ignore": + return SemicolonPreferenceIgnore + case "insert": + return SemicolonPreferenceInsert + case "remove": + return SemicolonPreferenceRemove + } + } + return SemicolonPreferenceIgnore +} + +type EditorSettings struct { + BaseIndentSize int + IndentSize int + TabSize int + NewLineCharacter string + ConvertTabsToSpaces bool + IndentStyle IndentStyle + TrimTrailingWhitespace bool +} + +type FormatCodeSettings struct { + EditorSettings + InsertSpaceAfterCommaDelimiter core.Tristate + InsertSpaceAfterSemicolonInForStatements core.Tristate + InsertSpaceBeforeAndAfterBinaryOperators core.Tristate + InsertSpaceAfterConstructor core.Tristate + InsertSpaceAfterKeywordsInControlFlowStatements core.Tristate + InsertSpaceAfterFunctionKeywordForAnonymousFunctions core.Tristate + InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis core.Tristate + InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets core.Tristate + InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces core.Tristate + InsertSpaceAfterOpeningAndBeforeClosingEmptyBraces core.Tristate + InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces core.Tristate + InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces core.Tristate + InsertSpaceAfterTypeAssertion core.Tristate + InsertSpaceBeforeFunctionParenthesis core.Tristate + PlaceOpenBraceOnNewLineForFunctions core.Tristate + PlaceOpenBraceOnNewLineForControlBlocks core.Tristate + InsertSpaceBeforeTypeAnnotation core.Tristate + IndentMultiLineObjectLiteralBeginningOnBlankLine core.Tristate + Semicolons SemicolonPreference + IndentSwitchCase core.Tristate +} + +func (settings *FormatCodeSettings) Parse(prefs any) bool { + formatSettingsMap, ok := prefs.(map[string]any) + formatSettingsParsed := false + if !ok { + return false + } + for name, value := range formatSettingsMap { + formatSettingsParsed = settings.Set(name, value) || formatSettingsParsed + } + return formatSettingsParsed +} + +func (settings *FormatCodeSettings) Set(name string, value any) bool { + switch strings.ToLower(name) { + case "baseindentsize": + settings.BaseIndentSize = ParseIntWithDefault(value, 0) + case "indentsize": + settings.IndentSize = ParseIntWithDefault(value, 4) + case "tabsize": + settings.TabSize = ParseIntWithDefault(value, 4) + case "newlinecharacter": + settings.NewLineCharacter = core.GetNewLineKind(tsoptions.ParseString(value)).GetNewLineCharacter() + case "converttabstospaces": + settings.ConvertTabsToSpaces = ParseBoolWithDefault(value, true) + case "indentstyle": + settings.IndentStyle = parseIndentStyle(value) + case "trimtrailingwhitespace": + settings.TrimTrailingWhitespace = ParseBoolWithDefault(value, true) + case "insertspaceaftercommadelimiter": + settings.InsertSpaceAfterCommaDelimiter = tsoptions.ParseTristate(value) + case "insertspaceaftersemicoloninformstatements": + settings.InsertSpaceAfterSemicolonInForStatements = tsoptions.ParseTristate(value) + case "insertspacebeforeandafterbinaryoperators": + settings.InsertSpaceBeforeAndAfterBinaryOperators = tsoptions.ParseTristate(value) + case "insertspaceafterconstructor": + settings.InsertSpaceAfterConstructor = tsoptions.ParseTristate(value) + case "insertspaceafterkeywordsincontrolflowstatements": + settings.InsertSpaceAfterKeywordsInControlFlowStatements = tsoptions.ParseTristate(value) + case "insertspaceafterfunctionkeywordforanonymousfunctions": + settings.InsertSpaceAfterFunctionKeywordForAnonymousFunctions = tsoptions.ParseTristate(value) + case "insertspaceafteropeningandbeforeclosingnonemptyparenthesis": + settings.InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis = tsoptions.ParseTristate(value) + case "insertspaceafteropeningandbeforeclosingnonemptybrackets": + settings.InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets = tsoptions.ParseTristate(value) + case "insertspaceafteropeningandbeforeclosingnonemptybraces": + settings.InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces = tsoptions.ParseTristate(value) + case "insertspaceafteropeningandbeforeclosingemptybraces": + settings.InsertSpaceAfterOpeningAndBeforeClosingEmptyBraces = tsoptions.ParseTristate(value) + case "insertspaceafteropeningandbeforeclosingtemplatesttringbraces": + settings.InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces = tsoptions.ParseTristate(value) + case "insertspaceafteropeningandbeforeclosingjsxexpressionbraces": + settings.InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces = tsoptions.ParseTristate(value) + case "insertspaceaftertypeassertion": + settings.InsertSpaceAfterTypeAssertion = tsoptions.ParseTristate(value) + case "insertspacebeforefunctionparenthesis": + settings.InsertSpaceBeforeFunctionParenthesis = tsoptions.ParseTristate(value) + case "placeopenbraceonnewlineforfunctions": + settings.PlaceOpenBraceOnNewLineForFunctions = tsoptions.ParseTristate(value) + case "placeopenbraceonnewlineforcontrolblocks": + settings.PlaceOpenBraceOnNewLineForControlBlocks = tsoptions.ParseTristate(value) + case "insertspacebeforetypeannotation": + settings.InsertSpaceBeforeTypeAnnotation = tsoptions.ParseTristate(value) + case "indentmultilineobjectliteralbeginningonblankline": + settings.IndentMultiLineObjectLiteralBeginningOnBlankLine = tsoptions.ParseTristate(value) + case "semicolons": + settings.Semicolons = parseSemicolonPreference(value) + case "indentswitchcase": + settings.IndentSwitchCase = tsoptions.ParseTristate(value) + default: + return false + } + return true +} + +func (settings *FormatCodeSettings) Copy() *FormatCodeSettings { + if settings == nil { + return nil + } + copied := *settings + return &copied +} + +func GetDefaultFormatCodeSettings() *FormatCodeSettings { + return &FormatCodeSettings{ + EditorSettings: EditorSettings{ + IndentSize: 4, + TabSize: 4, + NewLineCharacter: "\n", + ConvertTabsToSpaces: true, + IndentStyle: IndentStyleSmart, + TrimTrailingWhitespace: true, + }, + InsertSpaceAfterConstructor: core.TSFalse, + InsertSpaceAfterCommaDelimiter: core.TSTrue, + InsertSpaceAfterSemicolonInForStatements: core.TSTrue, + InsertSpaceBeforeAndAfterBinaryOperators: core.TSTrue, + InsertSpaceAfterKeywordsInControlFlowStatements: core.TSTrue, + InsertSpaceAfterFunctionKeywordForAnonymousFunctions: core.TSFalse, + InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: core.TSFalse, + InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: core.TSFalse, + InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: core.TSTrue, + InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: core.TSFalse, + InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: core.TSFalse, + InsertSpaceBeforeFunctionParenthesis: core.TSFalse, + PlaceOpenBraceOnNewLineForFunctions: core.TSFalse, + PlaceOpenBraceOnNewLineForControlBlocks: core.TSFalse, + Semicolons: SemicolonPreferenceIgnore, + IndentSwitchCase: core.TSTrue, + } +} diff --git a/internal/ls/lsutil/userpreferences.go b/internal/ls/lsutil/userpreferences.go index 4c6dbb22f2..b3f2e05db3 100644 --- a/internal/ls/lsutil/userpreferences.go +++ b/internal/ls/lsutil/userpreferences.go @@ -11,6 +11,8 @@ import ( func NewDefaultUserPreferences() *UserPreferences { return &UserPreferences{ + FormatCodeSettings: GetDefaultFormatCodeSettings(), + IncludeCompletionsForModuleExports: core.TSTrue, IncludeCompletionsForImportStatements: core.TSTrue, @@ -23,6 +25,8 @@ func NewDefaultUserPreferences() *UserPreferences { } type UserPreferences struct { + *FormatCodeSettings + QuotePreference QuotePreference LazyConfiguredProjectsFromExternalProject bool // !!! @@ -349,37 +353,25 @@ func (p *UserPreferences) ModuleSpecifierPreferences() modulespecifiers.UserPref // ------ Parsing Config Response ------- -// returns non-nil if should break loop -func (p *UserPreferences) Parse(item any) *UserPreferences { - if item == nil { - // continue - } else if config, ok := item.(map[string]any); ok { - p.parseWorker(config) - } else if item, ok := item.(*UserPreferences); ok { - // case for fourslash - return item.CopyOrDefault() - } - return nil -} - -func (p *UserPreferences) parseWorker(config map[string]any) { +func (p *UserPreferences) ParseWorker(config map[string]any) *UserPreferences { // Process unstable preferences first so that they do not overwrite stable properties if unstable, ok := config["unstable"]; ok { // unstable properties must be named the same as userPreferences - p.parseAll(unstable) + p.ParseAll(unstable) } + formatSettingsParsed := false for name, values := range config { switch name { case "unstable": continue case "inlayHints": - p.parseInlayHints(values) + p.ParseInlayHints(values) case "suggest": - p.parseSuggest(values) + p.ParseSuggest(values) case "preferences": - p.parsePreferences(values) + p.ParsePreferences(values) case "format": - // !!! + formatSettingsParsed = p.FormatCodeSettings.Parse(values) || formatSettingsParsed case "tsserver": // !!! case "tsc": @@ -387,22 +379,156 @@ func (p *UserPreferences) parseWorker(config map[string]any) { case "experimental": // !!! default: - p.set(name, values) + p.Set(name, values) + formatSettingsParsed = p.FormatCodeSettings.Set(name, values) || formatSettingsParsed + } + } + if !formatSettingsParsed { + p.FormatCodeSettings = nil + } + return p +} + +func (p *UserPreferences) Set(name string, value any) bool { + switch strings.ToLower(name) { + case "quotePreference": + p.QuotePreference = parseQuotePreference(value) + case "lazyconfiguredprojectsfromexternalproject": + p.LazyConfiguredProjectsFromExternalProject = ParseBoolWithDefault(value, false) + case "maximumhoverlength": + p.MaximumHoverLength = ParseIntWithDefault(value, 500) + case "includecompletionsformoduleexports": + p.IncludeCompletionsForModuleExports = tsoptions.ParseTristate(value) + case "includecompletionsforimportstatements": + p.IncludeCompletionsForImportStatements = tsoptions.ParseTristate(value) + case "includeautomaticoptionalchaincompletions": + p.IncludeAutomaticOptionalChainCompletions = tsoptions.ParseTristate(value) + case "includecompletionswithsnippettext": + p.IncludeCompletionsWithSnippetText = tsoptions.ParseTristate(value) + case "includecompletionswithclassmembersnippets": + p.IncludeCompletionsWithClassMemberSnippets = tsoptions.ParseTristate(value) + case "includecompletionswithobjectliteralmethodsnippets": + p.IncludeCompletionsWithObjectLiteralMethodSnippets = tsoptions.ParseTristate(value) + case "jsxattributecompletionstyle": + p.JsxAttributeCompletionStyle = parseJsxAttributeCompletionStyle(value) + case "importmodulespecifierpreference": + p.ImportModuleSpecifierPreference = parseImportModuleSpecifierPreference(value) + case "importmodulespecifierending": + p.ImportModuleSpecifierEnding = parseImportModuleSpecifierEndingPreference(value) + case "includepackagejsonautoimports": + p.IncludePackageJsonAutoImports = parseIncludePackageJsonAutoImports(value) + case "autoimportspecifierexcluderegexes": + p.AutoImportSpecifierExcludeRegexes = tsoptions.ParseStringArray(value) + case "autoimportfileexcludepatterns": + p.AutoImportFileExcludePatterns = tsoptions.ParseStringArray(value) + case "prefertypeonlyautoimports": + p.PreferTypeOnlyAutoImports = ParseBoolWithDefault(value, false) + case "organizeimportsignorecase": + p.OrganizeImportsIgnoreCase = tsoptions.ParseTristate(value) + case "organizeimportscollation": + p.OrganizeImportsCollation = parseOrganizeImportsCollation(value) + case "organizeimportslocale": + p.OrganizeImportsLocale = tsoptions.ParseString(value) + case "organizeimportsnumericcollation": + p.OrganizeImportsNumericCollation = ParseBoolWithDefault(value, false) + case "organizeimportsaccentcollation": + p.OrganizeImportsAccentCollation = ParseBoolWithDefault(value, true) + case "organizeimportscasefirst": + p.OrganizeImportsCaseFirst = parseOrganizeImportsCaseFirst(value) + case "organizeimportstypeorder": + p.OrganizeImportsTypeOrder = parseOrganizeImportsTypeOrder(value) + case "allowtextchangesinnewfiles": + p.AllowTextChangesInNewFiles = ParseBoolWithDefault(value, true) // !!! + case "usealiasesforrename", "provideprefixandsuffixtextforrename": + p.UseAliasesForRename = tsoptions.ParseTristate(value) + case "allowrenameofimportpath": + p.AllowRenameOfImportPath = ParseBoolWithDefault(value, true) + case "providerefactornotapplicablereason": + p.ProvideRefactorNotApplicableReason = ParseBoolWithDefault(value, true) + case "includeinlayparameternamehints": + p.IncludeInlayParameterNameHints = parseInlayParameterNameHints(value) + case "includeinlayparameternamehintswhenargumentmatchesname": + p.IncludeInlayParameterNameHintsWhenArgumentMatchesName = ParseBoolWithDefault(value, false) + case "includeinlayfunctionparametertypeHints": + p.IncludeInlayFunctionParameterTypeHints = ParseBoolWithDefault(value, false) + case "includeinlayvariabletypehints": + p.IncludeInlayVariableTypeHints = ParseBoolWithDefault(value, false) + case "includeinlayvariabletypehintswhentypematchesname": + p.IncludeInlayVariableTypeHintsWhenTypeMatchesName = ParseBoolWithDefault(value, false) + case "includeinlaypropertydeclarationtypehints": + p.IncludeInlayPropertyDeclarationTypeHints = ParseBoolWithDefault(value, false) + case "includeinlayfunctionlikereturntypehints": + p.IncludeInlayFunctionLikeReturnTypeHints = ParseBoolWithDefault(value, false) + case "includeinlayenummembervaluehints": + p.IncludeInlayEnumMemberValueHints = ParseBoolWithDefault(value, false) + case "excludelibrarysymbolsinnavto": + p.ExcludeLibrarySymbolsInNavTo = ParseBoolWithDefault(value, false) + case "disablesuggestions": + p.DisableSuggestions = ParseBoolWithDefault(value, false) + case "disablelinetextinreferences": + p.DisableLineTextInReferences = ParseBoolWithDefault(value, true) + case "displaypartsforjsdoc": + p.DisplayPartsForJSDoc = ParseBoolWithDefault(value, true) + default: + if p.FormatCodeSettings == nil { + p.FormatCodeSettings = GetDefaultFormatCodeSettings() } + return p.FormatCodeSettings.Set(name, value) } + return true } -func (p *UserPreferences) parseAll(prefs any) { +func (p *UserPreferences) ParseOrganizeImportsPreferences(prefs any) { + // !!! this used to be in the typescript-language-features extension + prefsMap, ok := prefs.(map[string]any) + if !ok { + return + } + if typeOrder, ok := prefsMap["typeOrder"]; ok { + p.Set("organizeimportstypeorder", parseOrganizeImportsTypeOrder(typeOrder)) + } + if caseSensitivity, ok := prefsMap["caseSensitivity"]; ok { + if caseSensitivityStr, ok := caseSensitivity.(string); ok { + // default is already "auto" + switch caseSensitivityStr { + case "caseInsensitive": + p.OrganizeImportsIgnoreCase = core.TSTrue + case "caseSensitive": + p.OrganizeImportsIgnoreCase = core.TSFalse + } + } + } + if collation, ok := prefsMap["unicodeCollation"]; ok { + // The rest of the settings are only applicable when using unicode collation + if collationStr, ok := collation.(string); ok && collationStr == "unicode" { + p.Set("organizeimportscollation", OrganizeImportsCollationUnicode) + if locale, ok := prefsMap["locale"]; ok { + p.Set("organizeimportslocale", locale) + } + if numeric, ok := prefsMap["numericCollation"]; ok { + p.Set("organizeimportsnumericcollation", numeric) + } + if accent, ok := prefsMap["accentCollation"]; ok { + p.Set("organizeimportsaccentcollation", accent) + } + if caseFirst, ok := prefsMap["caseFirst"]; ok && !p.OrganizeImportsIgnoreCase.IsTrue() { + p.Set("organizeimportscasefirst", caseFirst) + } + } + } +} + +func (p *UserPreferences) ParseAll(prefs any) { prefsMap, ok := prefs.(map[string]any) if !ok { return } for name, value := range prefsMap { - p.set(name, value) + p.Set(name, value) } } -func (p *UserPreferences) parseInlayHints(prefs any) { +func (p *UserPreferences) ParseInlayHints(prefs any) { inlayHintsPreferences, ok := prefs.(map[string]any) if !ok { return @@ -413,7 +539,7 @@ func (p *UserPreferences) parseInlayHints(prefs any) { switch name { case "parameterNames": if enabled, ok := v["enabled"]; ok { - p.set("includeInlayParameterNameHints", enabled) + p.Set("includeInlayParameterNameHints", enabled) } p.IncludeInlayParameterNameHintsWhenArgumentMatchesName = parseSupress(v, "supressWhenArgumentMatchesName") case "parameterTypes": @@ -430,12 +556,12 @@ func (p *UserPreferences) parseInlayHints(prefs any) { } } else { // non-vscode case - p.set(name, v) + p.Set(name, v) } } } -func (p *UserPreferences) parseSuggest(prefs any) { +func (p *UserPreferences) ParseSuggest(prefs any) { completionsPreferences, ok := prefs.(map[string]any) if !ok { return @@ -443,73 +569,33 @@ func (p *UserPreferences) parseSuggest(prefs any) { for name, value := range completionsPreferences { switch name { case "autoImports": - p.set("includeCompletionsForModuleExports", value) + p.Set("includeCompletionsForModuleExports", value) case "objectLiteralMethodSnippets": if v, ok := value.(map[string]any); ok { - p.set("includeCompletionsWithObjectLiteralMethodSnippets", parseEnabledBool(v)) + p.Set("includeCompletionsWithObjectLiteralMethodSnippets", parseEnabledBool(v)) } case "classMemberSnippets": if v, ok := value.(map[string]any); ok { - p.set("includeCompletionsWithClassMemberSnippets", parseEnabledBool(v)) + p.Set("includeCompletionsWithClassMemberSnippets", parseEnabledBool(v)) } case "includeAutomaticOptionalChainCompletions": - p.set("includeAutomaticOptionalChainCompletions", value) + p.Set("includeAutomaticOptionalChainCompletions", value) case "includeCompletionsForImportStatements": - p.set("includeCompletionsForImportStatements", value) + p.Set("includeCompletionsForImportStatements", value) } } } -func (p *UserPreferences) parsePreferences(prefs any) { +func (p *UserPreferences) ParsePreferences(prefs any) { prefsMap, ok := prefs.(map[string]any) if !ok { return } for name, value := range prefsMap { if name == "organizeImports" { - p.parseOrganizeImportsPreferences(value) + p.ParseOrganizeImportsPreferences(value) } else { - p.set(name, value) - } - } -} - -func (p *UserPreferences) parseOrganizeImportsPreferences(prefs any) { - // !!! this used to be in the typescript-language-features extension - prefsMap, ok := prefs.(map[string]any) - if !ok { - return - } - if typeOrder, ok := prefsMap["typeOrder"]; ok { - p.set("organizeimportstypeorder", parseOrganizeImportsTypeOrder(typeOrder)) - } - if caseSensitivity, ok := prefsMap["caseSensitivity"]; ok { - if caseSensitivityStr, ok := caseSensitivity.(string); ok { - // default is already "auto" - switch caseSensitivityStr { - case "caseInsensitive": - p.OrganizeImportsIgnoreCase = core.TSTrue - case "caseSensitive": - p.OrganizeImportsIgnoreCase = core.TSFalse - } - } - } - if collation, ok := prefsMap["unicodeCollation"]; ok { - // The rest of the settings are only applicable when using unicode collation - if collationStr, ok := collation.(string); ok && collationStr == "unicode" { - p.set("organizeimportscollation", OrganizeImportsCollationUnicode) - if locale, ok := prefsMap["locale"]; ok { - p.set("organizeimportslocale", locale) - } - if numeric, ok := prefsMap["numericCollation"]; ok { - p.set("organizeimportsnumericcollation", numeric) - } - if accent, ok := prefsMap["accentCollation"]; ok { - p.set("organizeimportsaccentcollation", accent) - } - if caseFirst, ok := prefsMap["caseFirst"]; ok && !p.OrganizeImportsIgnoreCase.IsTrue() { - p.set("organizeimportscasefirst", caseFirst) - } + p.Set(name, value) } } } @@ -534,99 +620,16 @@ func parseSupress(v map[string]any, name string) bool { return false } -func parseBoolWithDefault(val any, defaultV bool) bool { +func ParseBoolWithDefault(val any, defaultV bool) bool { if v, ok := val.(bool); ok { return v } return defaultV } -func parseIntWithDefault(val any, defaultV int) int { +func ParseIntWithDefault(val any, defaultV int) int { if v, ok := val.(int); ok { return v } return defaultV } - -func (p *UserPreferences) set(name string, value any) { - switch strings.ToLower(name) { - case "quotePreference": - p.QuotePreference = parseQuotePreference(value) - case "lazyconfiguredprojectsfromexternalproject": - p.LazyConfiguredProjectsFromExternalProject = parseBoolWithDefault(value, false) - case "maximumhoverlength": - p.MaximumHoverLength = parseIntWithDefault(value, 500) - case "includecompletionsformoduleexports": - p.IncludeCompletionsForModuleExports = tsoptions.ParseTristate(value) - case "includecompletionsforimportstatements": - p.IncludeCompletionsForImportStatements = tsoptions.ParseTristate(value) - case "includeautomaticoptionalchaincompletions": - p.IncludeAutomaticOptionalChainCompletions = tsoptions.ParseTristate(value) - case "includecompletionswithsnippettext": - p.IncludeCompletionsWithSnippetText = tsoptions.ParseTristate(value) - case "includecompletionswithclassmembersnippets": - p.IncludeCompletionsWithClassMemberSnippets = tsoptions.ParseTristate(value) - case "includecompletionswithobjectliteralmethodsnippets": - p.IncludeCompletionsWithObjectLiteralMethodSnippets = tsoptions.ParseTristate(value) - case "jsxattributecompletionstyle": - p.JsxAttributeCompletionStyle = parseJsxAttributeCompletionStyle(value) - case "importmodulespecifierpreference": - p.ImportModuleSpecifierPreference = parseImportModuleSpecifierPreference(value) - case "importmodulespecifierending": - p.ImportModuleSpecifierEnding = parseImportModuleSpecifierEndingPreference(value) - case "includepackagejsonautoimports": - p.IncludePackageJsonAutoImports = parseIncludePackageJsonAutoImports(value) - case "autoimportspecifierexcluderegexes": - p.AutoImportSpecifierExcludeRegexes = tsoptions.ParseStringArray(value) - case "autoimportfileexcludepatterns": - p.AutoImportFileExcludePatterns = tsoptions.ParseStringArray(value) - case "prefertypeonlyautoimports": - p.PreferTypeOnlyAutoImports = parseBoolWithDefault(value, false) - case "organizeimportsignorecase": - p.OrganizeImportsIgnoreCase = tsoptions.ParseTristate(value) - case "organizeimportscollation": - p.OrganizeImportsCollation = parseOrganizeImportsCollation(value) - case "organizeimportslocale": - p.OrganizeImportsLocale = tsoptions.ParseString(value) - case "organizeimportsnumericcollation": - p.OrganizeImportsNumericCollation = parseBoolWithDefault(value, false) - case "organizeimportsaccentcollation": - p.OrganizeImportsAccentCollation = parseBoolWithDefault(value, true) - case "organizeimportscasefirst": - p.OrganizeImportsCaseFirst = parseOrganizeImportsCaseFirst(value) - case "organizeimportstypeorder": - p.OrganizeImportsTypeOrder = parseOrganizeImportsTypeOrder(value) - case "allowtextchangesinnewfiles": - p.AllowTextChangesInNewFiles = parseBoolWithDefault(value, true) // !!! - case "usealiasesforrename", "provideprefixandsuffixtextforrename": - p.UseAliasesForRename = tsoptions.ParseTristate(value) - case "allowrenameofimportpath": - p.AllowRenameOfImportPath = parseBoolWithDefault(value, true) - case "providerefactornotapplicablereason": - p.ProvideRefactorNotApplicableReason = parseBoolWithDefault(value, true) - case "includeinlayparameternamehints": - p.IncludeInlayParameterNameHints = parseInlayParameterNameHints(value) - case "includeinlayparameternamehintswhenargumentmatchesname": - p.IncludeInlayParameterNameHintsWhenArgumentMatchesName = parseBoolWithDefault(value, false) - case "includeinlayfunctionparametertypeHints": - p.IncludeInlayFunctionParameterTypeHints = parseBoolWithDefault(value, false) - case "includeinlayvariabletypehints": - p.IncludeInlayVariableTypeHints = parseBoolWithDefault(value, false) - case "includeinlayvariabletypehintswhentypematchesname": - p.IncludeInlayVariableTypeHintsWhenTypeMatchesName = parseBoolWithDefault(value, false) - case "includeinlaypropertydeclarationtypehints": - p.IncludeInlayPropertyDeclarationTypeHints = parseBoolWithDefault(value, false) - case "includeinlayfunctionlikereturntypehints": - p.IncludeInlayFunctionLikeReturnTypeHints = parseBoolWithDefault(value, false) - case "includeinlayenummembervaluehints": - p.IncludeInlayEnumMemberValueHints = parseBoolWithDefault(value, false) - case "excludelibrarysymbolsinnavto": - p.ExcludeLibrarySymbolsInNavTo = parseBoolWithDefault(value, false) - case "disablesuggestions": - p.DisableSuggestions = parseBoolWithDefault(value, false) - case "disablelinetextinreferences": - p.DisableLineTextInReferences = parseBoolWithDefault(value, true) - case "displaypartsforjsdoc": - p.DisplayPartsForJSDoc = parseBoolWithDefault(value, true) - } -} diff --git a/internal/lsp/server.go b/internal/lsp/server.go index 29037f6c74..48891da469 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -16,7 +16,6 @@ import ( "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/ls" "github.com/microsoft/typescript-go/internal/ls/lsconv" - "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/lsp/lsproto" "github.com/microsoft/typescript-go/internal/project" "github.com/microsoft/typescript-go/internal/project/ata" @@ -220,31 +219,34 @@ func (s *Server) RefreshDiagnostics(ctx context.Context) error { return nil } -func (s *Server) RequestConfiguration(ctx context.Context) (*lsutil.UserPreferences, error) { +func (s *Server) RequestConfiguration(ctx context.Context) (*project.Config, error) { if s.initializeParams.Capabilities == nil || s.initializeParams.Capabilities.Workspace == nil || !ptrIsTrue(s.initializeParams.Capabilities.Workspace.Configuration) { // if no configuration request capapbility, return default preferences - return s.session.NewUserPreferences(), nil + return project.NewConfig(s.session.NewUserPreferences()), nil } result, err := s.sendRequest(ctx, lsproto.MethodWorkspaceConfiguration, &lsproto.ConfigurationParams{ Items: []*lsproto.ConfigurationItem{ { Section: ptrTo("typescript"), }, + { + Section: ptrTo("ts"), + }, + { + Section: ptrTo("javascript"), + }, + { + Section: ptrTo("js"), + }, }, }) if err != nil { - return nil, fmt.Errorf("configure request failed: %w", err) + return &project.Config{}, fmt.Errorf("configure request failed: %w", err) } configs := result.([]any) - s.Log(fmt.Sprintf("\n\nconfiguration: %+v, %T\n\n", configs, configs)) - userPreferences := s.session.NewUserPreferences() - for _, item := range configs { - if parsed := userPreferences.Parse(item); parsed != nil { - return parsed, nil - } - } - return userPreferences, nil + s.Log(fmt.Sprintf("\n\nconfiguration received: %+v, %T\n\n", configs, configs)) + return project.ParseConfiguration(configs), nil } func (s *Server) Run(ctx context.Context) error { @@ -732,9 +734,11 @@ func (s *Server) handleInitialized(ctx context.Context, params *lsproto.Initiali if s.initializeParams != nil && s.initializeParams.InitializationOptions != nil && *s.initializeParams.InitializationOptions != nil { // handle userPreferences from initializationOptions - userPreferences := s.session.NewUserPreferences() - userPreferences.Parse(*s.initializeParams.InitializationOptions) - s.session.InitializeWithConfig(userPreferences) + if v, ok := (*s.initializeParams.InitializationOptions).(map[string]any); ok { + // currently assume that preferences initalization options are ts options, so we parse them into config.ts. + // This is fine because if js options are never provided, they default to the ts options. + s.session.InitializeWithConfig(project.ParseConfiguration([]any{v})) + } } else { // request userPreferences if not provided at initialization userPreferences, err := s.RequestConfiguration(ctx) @@ -763,11 +767,13 @@ func (s *Server) handleExit(ctx context.Context, params any) error { func (s *Server) handleDidChangeWorkspaceConfiguration(ctx context.Context, params *lsproto.DidChangeConfigurationParams) error { // !!! only implemented because needed for fourslash - userPreferences := s.session.UserPreferences() - if parsed := userPreferences.Parse(params.Settings); parsed != nil { - userPreferences = parsed + if params.Settings == nil { + return nil + } else if settings, ok := params.Settings.([]any); ok { + s.session.Configure(project.ParseConfiguration(settings)) + } else { + s.session.Configure(project.ParseConfiguration([]any{params.Settings})) } - s.session.Configure(userPreferences) return nil } diff --git a/internal/project/configuration.go b/internal/project/configuration.go new file mode 100644 index 0000000000..7c49b5aec5 --- /dev/null +++ b/internal/project/configuration.go @@ -0,0 +1,60 @@ +package project + +import ( + "github.com/microsoft/typescript-go/internal/ls/lsutil" +) + +type Config struct { + js *lsutil.UserPreferences + ts *lsutil.UserPreferences + // tsserverOptions +} + +func NewConfig(userPreferences *lsutil.UserPreferences) *Config { + // use default userPreferences if nil + return &Config{ + js: userPreferences.CopyOrDefault(), + ts: userPreferences.CopyOrDefault(), + } +} + +func (c *Config) Copy() *Config { + return &Config{ + ts: c.ts.CopyOrDefault(), + js: c.js.CopyOrDefault(), + } +} + +// any non-nil field in b is copied into a +func (a *Config) CopyInto(b *Config) *Config { + if b.ts != nil { + a.ts = b.ts.Copy() + } + if b.js != nil { + a.js = b.js.Copy() + } + return a +} + +func ParseConfiguration(items []any) *Config { + defaultConfig := NewConfig(nil) + c := &Config{} + for i, item := range items { + if item == nil { + // continue + } else if config, ok := item.(map[string]any); ok { + newConfig := &Config{} + if i < 2 { + newConfig.ts = defaultConfig.ts.Copy().ParseWorker(config) + } else { + newConfig.js = defaultConfig.js.Copy().ParseWorker(config) + } + c = c.CopyInto(newConfig) + } else if item, ok := item.(*lsutil.UserPreferences); ok { + // case for fourslash -- fourslash sends the entire userPreferences over + // !!! support format and js/ts distinction? + return NewConfig(item) + } + } + return c +} diff --git a/internal/project/session.go b/internal/project/session.go index 0e2b2de6b1..25505fed21 100644 --- a/internal/project/session.go +++ b/internal/project/session.go @@ -81,8 +81,9 @@ type Session struct { programCounter *programCounter // read-only after initialization - initialPreferences *lsutil.UserPreferences - userPreferences *lsutil.UserPreferences // !!! update to Config + initialConfig *Config + // current config + workspaceConfig *Config compilerOptionsForInferredProjects *core.CompilerOptions typingsInstaller *ata.TypingsInstaller backgroundQueue *background.Queue @@ -158,9 +159,11 @@ func NewSession(init *SessionInit) *Session { extendedConfigCache, &ConfigFileRegistry{}, nil, - Config{}, + nil, toPath, ), + initialConfig: &Config{}, + workspaceConfig: &Config{}, pendingATAChanges: make(map[tspath.Path]*ATAStateChange), watches: make(map[fileSystemWatcherKey]*fileSystemWatcherValue), } @@ -185,16 +188,25 @@ func (s *Session) GetCurrentDirectory() string { return s.options.CurrentDirectory } -// Gets current UserPreferences, always a copy +// Gets current configuration, always a copy +func (s *Session) Config() Config { + s.configRWMu.Lock() + defer s.configRWMu.Unlock() + return *s.workspaceConfig.Copy() +} + +// !!! ts/js preferences +// Gets current configuration, always a copy func (s *Session) UserPreferences() *lsutil.UserPreferences { s.configRWMu.Lock() defer s.configRWMu.Unlock() - return s.userPreferences.Copy() + return s.workspaceConfig.ts.Copy() } +// !!! ts/js preferences // Gets original UserPreferences of the session func (s *Session) NewUserPreferences() *lsutil.UserPreferences { - return s.initialPreferences.CopyOrDefault() + return s.initialConfig.ts.CopyOrDefault() } // Trace implements module.ResolutionHost @@ -202,16 +214,17 @@ func (s *Session) Trace(msg string) { panic("ATA module resolution should not use tracing") } -func (s *Session) Configure(userPreferences *lsutil.UserPreferences) { +func (s *Session) Configure(config *Config) { s.configRWMu.Lock() defer s.configRWMu.Unlock() s.pendingConfigChanges = true - s.userPreferences = userPreferences + s.workspaceConfig = s.workspaceConfig.CopyInto(config) } -func (s *Session) InitializeWithConfig(userPreferences *lsutil.UserPreferences) { - s.initialPreferences = userPreferences.CopyOrDefault() - s.Configure(s.initialPreferences) +func (s *Session) InitializeWithConfig(config *Config) { + config.ts = config.ts.CopyOrDefault() + s.initialConfig = config + s.Configure(s.initialConfig) } func (s *Session) DidOpenFile(ctx context.Context, uri lsproto.DocumentUri, version int32, content string, languageKind lsproto.LanguageKind) { @@ -599,9 +612,7 @@ func (s *Session) flushChanges(ctx context.Context) (FileChangeSummary, map[tspa defer s.configRWMu.Unlock() var newConfig *Config if s.pendingConfigChanges { - newConfig = &Config{ - tsUserPreferences: s.userPreferences.Copy(), - } + newConfig = s.workspaceConfig.Copy() } s.pendingConfigChanges = false return fileChanges, overlays, pendingATAChanges, newConfig diff --git a/internal/project/snapshot.go b/internal/project/snapshot.go index 72af69381e..45d9296931 100644 --- a/internal/project/snapshot.go +++ b/internal/project/snapshot.go @@ -8,7 +8,6 @@ import ( "github.com/microsoft/typescript-go/internal/collections" "github.com/microsoft/typescript-go/internal/core" - "github.com/microsoft/typescript-go/internal/format" "github.com/microsoft/typescript-go/internal/ls/lsconv" "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/lsp/lsproto" @@ -35,7 +34,7 @@ type Snapshot struct { ProjectCollection *ProjectCollection ConfigFileRegistry *ConfigFileRegistry compilerOptionsForInferredProjects *core.CompilerOptions - config Config + config *Config builderLogs *logging.LogTree apiError error @@ -50,9 +49,12 @@ func NewSnapshot( extendedConfigCache *ExtendedConfigCache, configFileRegistry *ConfigFileRegistry, compilerOptionsForInferredProjects *core.CompilerOptions, - config Config, + config *Config, toPath func(fileName string) tspath.Path, ) *Snapshot { + if config == nil { + config = NewConfig(nil) // disallow nil config + } s := &Snapshot{ id: id, @@ -95,11 +97,11 @@ func (s *Snapshot) GetECMALineInfo(fileName string) *sourcemap.ECMALineInfo { } func (s *Snapshot) UserPreferences() *lsutil.UserPreferences { - return s.config.tsUserPreferences + return s.config.ts } -func (s *Snapshot) FormatOptions() *format.FormatCodeSettings { - return s.config.formatOptions +func (s *Snapshot) FormatOptions() *lsutil.FormatCodeSettings { + return s.config.ts.FormatCodeSettings } func (s *Snapshot) Converters() *lsconv.Converters { @@ -145,13 +147,6 @@ type SnapshotChange struct { apiRequest *APISnapshotRequest } -type Config struct { - tsUserPreferences *lsutil.UserPreferences - // jsUserPreferences *lsutil.UserPreferences - formatOptions *format.FormatCodeSettings - // tsserverOptions -} - // ATAStateChange represents a change to a project's ATA state. type ATAStateChange struct { ProjectID tspath.Path @@ -282,12 +277,7 @@ func (s *Snapshot) Clone(ctx context.Context, change SnapshotChange, overlays ma config := s.config if change.newConfig != nil { - if change.newConfig.tsUserPreferences != nil { - config.tsUserPreferences = change.newConfig.tsUserPreferences.CopyOrDefault() - } - if change.newConfig.formatOptions != nil { - config.formatOptions = change.newConfig.formatOptions - } + config.CopyInto(change.newConfig) } snapshotFS, _ := fs.Finalize() From 48bdad28f0b7bdea0a47d727e7eb68c5a4be1f17 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Tue, 2 Dec 2025 15:46:00 -0800 Subject: [PATCH 2/5] merge --- internal/execute/tsc.go | 2 +- internal/ls/lsutil/formatcodeoptions.go | 10 +++++----- internal/lsp/server.go | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/internal/execute/tsc.go b/internal/execute/tsc.go index fb6855b8c7..db7919eb96 100644 --- a/internal/execute/tsc.go +++ b/internal/execute/tsc.go @@ -15,8 +15,8 @@ import ( "github.com/microsoft/typescript-go/internal/execute/tsc" "github.com/microsoft/typescript-go/internal/format" "github.com/microsoft/typescript-go/internal/jsonutil" - "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/locale" + "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/parser" "github.com/microsoft/typescript-go/internal/pprof" "github.com/microsoft/typescript-go/internal/tsoptions" diff --git a/internal/ls/lsutil/formatcodeoptions.go b/internal/ls/lsutil/formatcodeoptions.go index cd7994f087..04cf14c1e5 100644 --- a/internal/ls/lsutil/formatcodeoptions.go +++ b/internal/ls/lsutil/formatcodeoptions.go @@ -101,19 +101,19 @@ func (settings *FormatCodeSettings) Parse(prefs any) bool { func (settings *FormatCodeSettings) Set(name string, value any) bool { switch strings.ToLower(name) { case "baseindentsize": - settings.BaseIndentSize = ParseIntWithDefault(value, 0) + settings.BaseIndentSize = parseIntWithDefault(value, 0) case "indentsize": - settings.IndentSize = ParseIntWithDefault(value, 4) + settings.IndentSize = parseIntWithDefault(value, 4) case "tabsize": - settings.TabSize = ParseIntWithDefault(value, 4) + settings.TabSize = parseIntWithDefault(value, 4) case "newlinecharacter": settings.NewLineCharacter = core.GetNewLineKind(tsoptions.ParseString(value)).GetNewLineCharacter() case "converttabstospaces": - settings.ConvertTabsToSpaces = ParseBoolWithDefault(value, true) + settings.ConvertTabsToSpaces = parseBoolWithDefault(value, true) case "indentstyle": settings.IndentStyle = parseIndentStyle(value) case "trimtrailingwhitespace": - settings.TrimTrailingWhitespace = ParseBoolWithDefault(value, true) + settings.TrimTrailingWhitespace = parseBoolWithDefault(value, true) case "insertspaceaftercommadelimiter": settings.InsertSpaceAfterCommaDelimiter = tsoptions.ParseTristate(value) case "insertspaceaftersemicoloninformstatements": diff --git a/internal/lsp/server.go b/internal/lsp/server.go index e65c6403ec..6623560aa8 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -270,7 +270,6 @@ func (s *Server) RequestConfiguration(ctx context.Context) (*project.Config, err if err != nil { return &project.Config{}, fmt.Errorf("configure request failed: %w", err) } - configs := result.([]any) s.Log(fmt.Sprintf("\n\nconfiguration received: %+v, %T\n\n", configs, configs)) return project.ParseConfiguration(configs), nil } @@ -1078,7 +1077,7 @@ func (s *Server) handleDidChangeWorkspaceConfiguration(ctx context.Context, para } else if settings, ok := params.Settings.([]any); ok { s.session.Configure(project.ParseConfiguration(settings)) } else if settings, ok := params.Settings.(map[string]any); ok { - s.session.Configure(project.ParseConfiguration([]any{settings["typescript", "ts", "javascript", "js"]})) + s.session.Configure(project.ParseConfiguration([]any{settings["typescript"], settings["ts"], settings["javascript"], settings["js"]})) } return nil } From ca7810519924c34380f0a13d168047e3355a7dbc Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Fri, 12 Dec 2025 13:09:17 -0800 Subject: [PATCH 3/5] formatting --- internal/format/span.go | 5 +- .../fourslash/_scripts/convertFourslash.mts | 98 +++ internal/fourslash/_scripts/failingTests.txt | 93 +++ internal/fourslash/fourslash.go | 208 +++++- .../tests/gen/asOperatorFormatting_test.go | 20 + .../tests/gen/autoFormattingOnPasting_test.go | 27 + .../tests/gen/autoImportProvider1_test.go | 34 + .../tests/gen/autoImportProvider2_test.go | 35 + .../tests/gen/autoImportProvider7_test.go | 76 ++ .../tests/gen/autoImportProvider8_test.go | 76 ++ .../gen/chainedFatArrowFormatting_test.go | 20 + .../tests/gen/commentsBlocks_test.go | 67 ++ ..._addToNamedWithDifferentCacheValue_test.go | 96 +++ ...nsImport_jsModuleExportsAssignment_test.go | 88 +++ ...onsOfObjectsInAListAfterFormatting_test.go | 24 + .../gen/constructorBraceFormatting_test.go | 23 + .../gen/forceIndentAfterNewLineInsert_test.go | 36 + internal/fourslash/tests/gen/format01_test.go | 21 + .../gen/formatAfterMultilineComment_test.go | 21 + .../gen/formatAfterObjectLiteral_test.go | 20 + .../gen/formatAfterPasteInString_test.go | 22 + .../tests/gen/formatAfterWhitespace_test.go | 29 + .../tests/gen/formatAnyTypeLiteral_test.go | 22 + .../gen/formatArrayLiteralExpression_test.go | 56 ++ ...rrayOrObjectLiteralsInVariableList_test.go | 20 + .../tests/gen/formatAsyncClassMethod1_test.go | 23 + .../tests/gen/formatAsyncClassMethod2_test.go | 23 + .../gen/formatAsyncComputedMethod_test.go | 22 + .../tests/gen/formatAsyncKeyword_test.go | 26 + .../gen/formatBracketInSwitchCase_test.go | 24 + .../tests/gen/formatColonAndQMark_test.go | 29 + .../tests/gen/formatComments_test.go | 36 + .../gen/formatConflictDiff3Marker1_test.go | 35 + .../tests/gen/formatConflictMarker1_test.go | 31 + .../gen/formatControlFlowConstructs_test.go | 22 + .../tests/gen/formatDebuggerStatement_test.go | 23 + ...DocumentPreserveTrailingWhitespace_test.go | 38 + .../tests/gen/formatDocumentWithJSDoc_test.go | 41 ++ .../gen/formatDocumentWithTrivia_test.go | 63 ++ .../tests/gen/formatDotAfterNumber_test.go | 32 + .../tests/gen/formatEmptyBlock_test.go | 21 + .../tests/gen/formatEmptyParamList_test.go | 20 + .../tests/gen/formatExportAssignment_test.go | 19 + .../tests/gen/formatIfTryCatchBlocks_test.go | 40 + .../gen/formatIfWithEmptyCondition_test.go | 23 + .../tests/gen/formatImplicitModule_test.go | 24 + .../tests/gen/formatImportDeclaration_test.go | 31 + .../tests/gen/formatInTryCatchFinally_test.go | 26 + .../tests/gen/formatInTsxFiles_test.go | 21 + ...eAfterCloseBraceBeforeCloseBracket_test.go | 20 + .../formatJsxWithKeywordInIdentifier_test.go | 20 + ...teralTypeInUnionOrIntersectionType_test.go | 49 ++ .../tests/gen/formatMultilineComment_test.go | 58 ++ .../formatMultilineTypesWithMapped_test.go | 87 +++ .../formatMultipleFunctionArguments_test.go | 57 ++ ...NestedClassWithOpenBraceOnNewLines_test.go | 31 + ...tNoSpaceAfterTemplateHeadAndMiddle_test.go | 49 ++ .../formatNoSpaceBeforeCloseBrace1_test.go | 19 + .../formatNoSpaceBeforeCloseBrace2_test.go | 19 + .../formatNoSpaceBeforeCloseBrace3_test.go | 21 + .../formatNoSpaceBeforeCloseBrace4_test.go | 21 + .../formatNoSpaceBeforeCloseBrace5_test.go | 21 + .../formatNoSpaceBeforeCloseBrace6_test.go | 21 + .../gen/formatNoSpaceBeforeCloseBrace_test.go | 19 + ...tweenClosingParenAndTemplateString_test.go | 21 + ...attern_restElementWithPropertyName_test.go | 19 + .../gen/formatObjectBindingPattern_test.go | 25 + .../formatOnEnterFunctionDeclaration_test.go | 21 + .../tests/gen/formatOnEnterInComment_test.go | 25 + .../formatOnEnterOpenBraceAddNewLine_test.go | 35 + ...ormatOnOpenCurlyBraceRemoveNewLine_test.go | 22 + .../gen/formatOnSemiColonAfterBreak_test.go | 22 + .../tests/gen/formatParameter_test.go | 35 + .../formatRemoveNewLineAfterOpenBrace_test.go | 27 + ...veSpaceBetweenDotDotDotAndTypeName_test.go | 23 + .../gen/formatSatisfiesExpression_test.go | 25 + .../formatSpaceAfterImplementsExtends_test.go | 39 + ...matSpaceAfterTemplateHeadAndMiddle_test.go | 49 ++ ...tSpaceBetweenFunctionAndArrayIndex_test.go | 32 + .../gen/formatTSXWithInlineComment_test.go | 24 + .../tests/gen/formatTryCatch_test.go | 29 + .../tests/gen/formatTryFinally_test.go | 27 + .../gen/formatTsxClosingAfterJsxText_test.go | 44 ++ .../formatTsxMultilineAttributeString_test.go | 30 + .../fourslash/tests/gen/formatTsx_test.go | 20 + .../tests/gen/formatTypeAnnotation1_test.go | 28 + .../tests/gen/formatTypeAnnotation2_test.go | 27 + .../gen/formatTypeArgumentOnNewLine_test.go | 30 + .../tests/gen/formatTypeParameters_test.go | 20 + .../gen/formatVariableDeclarationList_test.go | 54 ++ .../tests/gen/formatWithStatement_test.go | 45 ++ .../fourslash/tests/gen/formatonkey01_test.go | 26 + .../formattingAfterChainedFatArrow_test.go | 24 + ...ormattingAfterMultiLineIfCondition_test.go | 26 + .../formattingAfterMultiLineString_test.go | 26 + .../tests/gen/formattingArrayLiteral_test.go | 41 ++ .../tests/gen/formattingAwait_test.go | 27 + .../gen/formattingBlockInCaseClauses_test.go | 25 + .../gen/formattingChainingMethods_test.go | 57 ++ .../tests/gen/formattingComma_test.go | 50 ++ .../formattingCommentsBeforeErrors_test.go | 33 + .../gen/formattingConditionalOperator_test.go | 20 + .../gen/formattingConditionalTypes_test.go | 23 + .../tests/gen/formattingCrash_test.go | 23 + .../tests/gen/formattingDecorators_test.go | 125 ++++ .../gen/formattingDoubleLessThan_test.go | 20 + .../gen/formattingElseInsideAFunction_test.go | 26 + ...tingEqualsBeforeBracketInTypeAlias_test.go | 20 + ...formattingExpressionsInIfCondition_test.go | 24 + .../gen/formattingFatArrowFunctions_test.go | 306 ++++++++ .../tests/gen/formattingForIn_test.go | 20 + .../gen/formattingForLoopSemicolons_test.go | 34 + .../tests/gen/formattingForOfKeyword_test.go | 20 + .../gen/formattingGlobalAugmentation1_test.go | 21 + .../gen/formattingGlobalAugmentation2_test.go | 23 + .../tests/gen/formattingHexLiteral_test.go | 18 + .../tests/gen/formattingIfInElseBlock_test.go | 25 + .../gen/formattingIllegalImportClause_test.go | 35 + .../tests/gen/formattingInComment_test.go | 26 + .../gen/formattingInDestructuring1_test.go | 35 + .../gen/formattingInDestructuring2_test.go | 22 + .../gen/formattingInDestructuring3_test.go | 32 + .../gen/formattingInDestructuring4_test.go | 30 + .../gen/formattingInDestructuring5_test.go | 27 + .../gen/formattingInExpressionsInTsx_test.go | 27 + .../gen/formattingInMultilineComments_test.go | 26 + .../tests/gen/formattingJsxTexts1_test.go | 128 ++++ .../tests/gen/formattingJsxTexts2_test.go | 90 +++ .../tests/gen/formattingJsxTexts3_test.go | 32 + .../tests/gen/formattingJsxTexts4_test.go | 28 + .../gen/formattingKeywordAsIdentifier_test.go | 20 + .../tests/gen/formattingMappedType_test.go | 24 + ...rmattingMultilineCommentsWithTabs1_test.go | 42 ++ ...ormattingMultilineTemplateLiterals_test.go | 26 + .../tests/gen/formattingNestedScopes_test.go | 38 + ...formattingNonNullAssertionOperator_test.go | 32 + ...tLiteralOpenCurlyNewlineAssignment_test.go | 55 ++ ...bjectLiteralOpenCurlyNewlineTyping_test.go | 40 + ...ttingObjectLiteralOpenCurlyNewline_test.go | 52 ++ ...ngObjectLiteralOpenCurlySingleLine_test.go | 33 + .../tests/gen/formattingObjectLiteral_test.go | 22 + .../gen/formattingOfChainedLambda_test.go | 20 + .../gen/formattingOfExportDefault_test.go | 25 + ...rmattingOfMultilineBlockConstructs_test.go | 81 +++ ...hainedCallbacksAndPropertyAccesses_test.go | 46 ++ .../tests/gen/formattingOnClasses_test.go | 233 ++++++ .../tests/gen/formattingOnCloseBrace_test.go | 22 + .../gen/formattingOnClosingBracket_test.go | 104 +++ .../gen/formattingOnCommaOperator_test.go | 26 + .../formattingOnConstructorSignature_test.go | 23 + .../formattingOnDoWhileNoSemicolon_test.go | 31 + .../formattingOnDocumentReadyFunction_test.go | 26 + .../formattingOnEmptyInterfaceLiteral_test.go | 39 + .../gen/formattingOnEnterInComments_test.go | 26 + .../gen/formattingOnEnterInStrings_test.go | 22 + .../tests/gen/formattingOnEnter_test.go | 25 + .../tests/gen/formattingOnInterfaces_test.go | 22 + .../gen/formattingOnInvalidCodes_test.go | 281 +++++++ .../gen/formattingOnModuleIndentation_test.go | 26 + .../formattingOnNestedDoWhileByEnter_test.go | 37 + .../gen/formattingOnObjectLiteral_test.go | 98 +++ .../formattingOnOpenBraceOfFunctions_test.go | 23 + .../tests/gen/formattingOnSemiColon_test.go | 20 + .../gen/formattingOnSingleLineBlocks_test.go | 23 + ...mattingOnStatementsWithNoSemicolon_test.go | 184 +++++ .../formattingOnTabAfterCloseCurly_test.go | 45 ++ .../tests/gen/formattingOnVariety_test.go | 66 ++ .../tests/gen/formattingQMark_test.go | 25 + .../tests/gen/formattingReadonly_test.go | 25 + .../tests/gen/formattingRegexes_test.go | 20 + .../formattingReplaceTabsWithSpaces_test.go | 40 + ...tingSingleLineWithNewLineOptionSet_test.go | 32 + .../tests/gen/formattingSkippedTokens_test.go | 35 + ...tingSpaceAfterCommaBeforeOpenParen_test.go | 24 + .../formattingSpaceBeforeCloseParen_test.go | 45 ++ ...formattingSpaceBeforeFunctionParen_test.go | 40 + ...attingSpaceBetweenOptionalChaining_test.go | 23 + .../gen/formattingSpaceBetweenParent_test.go | 27 + .../formattingSpacesAfterConstructor_test.go | 25 + .../formattingTemplatesWithNewline_test.go | 22 + .../tests/gen/formattingTemplates_test.go | 24 + .../tests/gen/formattingTypeInfer_test.go | 50 ++ .../tests/gen/formattingVoid_test.go | 36 + .../formattingWithMultilineComments_test.go | 22 + ...mattingofSingleLineBlockConstructs_test.go | 53 ++ .../tests/gen/functionFormatting_test.go | 21 + .../tests/gen/functionIndentation_test.go | 93 +++ .../tests/gen/functionTypeFormatting_test.go | 20 + .../functionTypePredicateFormatting_test.go | 20 + .../generatorDeclarationFormatting_test.go | 23 + .../gen/genericsFormattingMultiline_test.go | 85 +++ .../tests/gen/genericsFormatting_test.go | 56 ++ ...tNameCodeFix_externalNonRelateive2_test.go | 56 ++ ...rtNameCodeFix_externalNonRelative1_test.go | 65 ++ .../tests/gen/importTypeFormatting_test.go | 21 + .../indentAfterFunctionClosingBraces_test.go | 25 + .../tests/gen/indentationInJsx3_test.go | 42 ++ .../multilineCommentBeforeOpenBrace_test.go | 31 + .../gen/optionalPropertyFormatting_test.go | 25 + internal/fourslash/tests/gen/paste_test.go | 20 + ...micolonFormattingAfterArrayLiteral_test.go | 20 + .../semicolonFormattingInsideAComment_test.go | 20 + ...olonFormattingInsideAStringLiteral_test.go | 20 + ...emicolonFormattingNestedStatements_test.go | 29 + .../tests/gen/semicolonFormatting_test.go | 20 + .../singleLineTypeLiteralFormatting_test.go | 20 + .../tests/gen/smartIndentNamedImport_test.go | 29 + .../tests/gen/spaceAfterConstructor_test.go | 25 + .../tests/gen/spaceAfterReturn_test.go | 28 + .../gen/spaceAfterStatementConditions_test.go | 61 ++ ...spaceBeforeAndAfterBinaryOperators_test.go | 38 + ...ingAfterNewlineInsertedBeforeWhile_test.go | 22 + .../gen/typeAssertionsFormatting_test.go | 23 + ...unclosedStringLiteralAutoformating_test.go | 22 + ...iteSpaceBeforeReturnTypeFormatting_test.go | 20 + .../tests/gen/whiteSpaceTrimming2_test.go | 29 + .../tests/gen/whiteSpaceTrimming3_test.go | 22 + .../tests/gen/whiteSpaceTrimming4_test.go | 20 + .../tests/gen/whiteSpaceTrimming_test.go | 25 + internal/ls/format.go | 20 +- internal/ls/lsutil/formatcodeoptions.go | 20 + internal/ls/lsutil/userpreferences.go | 176 +---- internal/project/configuration.go | 12 +- internal/project/session.go | 36 +- internal/project/session_test.go | 7 +- internal/project/snapshot.go | 4 +- internal/scanner/scanner.go | 2 +- ...rceOfProjectReferenceRedirectEdit.baseline | 644 ++++++++++++++++ ...OfProjectReferenceRedirectEditEnd.baseline | 351 ++++++++- ...psRenameWithProjectReferencesEdit.baseline | 644 ++++++++++++++++ ...enameWithProjectReferencesEditEnd.baseline | 355 ++++++++- ...ationMapsRenameWithSourceMapsEdit.baseline | 578 +++++++++++++++ ...onMapsRenameWithSourceMapsEditEnd.baseline | 315 +++++++- ...nameWithSourceMapsNotSolutionEdit.baseline | 688 ++++++++++++++++++ ...eWithSourceMapsNotSolutionEditEnd.baseline | 381 +++++++++- ...terItsUpdateDoesNotIncludeTheFile.baseline | 283 ++++++- .../arrowFunctionErrorSpan.errors.txt | 8 +- .../arrowFunctionErrorSpan.errors.txt.diff | 38 + .../asyncFunctionNoReturnType.errors.txt | 2 +- .../asyncFunctionNoReturnType.errors.txt.diff | 11 + ...xtualTupleTypeParameterReadonly.errors.txt | 2 +- ...TupleTypeParameterReadonly.errors.txt.diff | 11 + .../noImplicitReturnsExclusions.errors.txt | 2 +- ...oImplicitReturnsExclusions.errors.txt.diff | 11 + ...nWithConstraintCheckingDeferred.errors.txt | 2 +- ...ConstraintCheckingDeferred.errors.txt.diff | 3 +- .../recursiveTypeRelations.errors.txt | 2 +- .../recursiveTypeRelations.errors.txt.diff | 11 + .../compiler/undeclaredModuleError.errors.txt | 2 +- .../undeclaredModuleError.errors.txt.diff | 11 + ...ExpressionNoModuleKindSpecified.errors.txt | 2 +- ...ssionNoModuleKindSpecified.errors.txt.diff | 11 + ...eta(module=commonjs,target=es5).errors.txt | 2 +- ...odule=commonjs,target=es5).errors.txt.diff | 11 + ...(module=commonjs,target=esnext).errors.txt | 2 +- ...le=commonjs,target=esnext).errors.txt.diff | 11 + ...tMeta(module=es2020,target=es5).errors.txt | 2 +- ...(module=es2020,target=es5).errors.txt.diff | 11 + ...ta(module=es2020,target=esnext).errors.txt | 2 +- ...dule=es2020,target=esnext).errors.txt.diff | 11 + ...tMeta(module=esnext,target=es5).errors.txt | 2 +- ...(module=esnext,target=es5).errors.txt.diff | 11 + ...ta(module=esnext,target=esnext).errors.txt | 2 +- ...dule=esnext,target=esnext).errors.txt.diff | 11 + 264 files changed, 12925 insertions(+), 281 deletions(-) create mode 100644 internal/fourslash/tests/gen/asOperatorFormatting_test.go create mode 100644 internal/fourslash/tests/gen/autoFormattingOnPasting_test.go create mode 100644 internal/fourslash/tests/gen/autoImportProvider1_test.go create mode 100644 internal/fourslash/tests/gen/autoImportProvider2_test.go create mode 100644 internal/fourslash/tests/gen/autoImportProvider7_test.go create mode 100644 internal/fourslash/tests/gen/autoImportProvider8_test.go create mode 100644 internal/fourslash/tests/gen/chainedFatArrowFormatting_test.go create mode 100644 internal/fourslash/tests/gen/commentsBlocks_test.go create mode 100644 internal/fourslash/tests/gen/completionsImport_addToNamedWithDifferentCacheValue_test.go create mode 100644 internal/fourslash/tests/gen/completionsImport_jsModuleExportsAssignment_test.go create mode 100644 internal/fourslash/tests/gen/consistenceOnIndentionsOfObjectsInAListAfterFormatting_test.go create mode 100644 internal/fourslash/tests/gen/constructorBraceFormatting_test.go create mode 100644 internal/fourslash/tests/gen/forceIndentAfterNewLineInsert_test.go create mode 100644 internal/fourslash/tests/gen/format01_test.go create mode 100644 internal/fourslash/tests/gen/formatAfterMultilineComment_test.go create mode 100644 internal/fourslash/tests/gen/formatAfterObjectLiteral_test.go create mode 100644 internal/fourslash/tests/gen/formatAfterPasteInString_test.go create mode 100644 internal/fourslash/tests/gen/formatAfterWhitespace_test.go create mode 100644 internal/fourslash/tests/gen/formatAnyTypeLiteral_test.go create mode 100644 internal/fourslash/tests/gen/formatArrayLiteralExpression_test.go create mode 100644 internal/fourslash/tests/gen/formatArrayOrObjectLiteralsInVariableList_test.go create mode 100644 internal/fourslash/tests/gen/formatAsyncClassMethod1_test.go create mode 100644 internal/fourslash/tests/gen/formatAsyncClassMethod2_test.go create mode 100644 internal/fourslash/tests/gen/formatAsyncComputedMethod_test.go create mode 100644 internal/fourslash/tests/gen/formatAsyncKeyword_test.go create mode 100644 internal/fourslash/tests/gen/formatBracketInSwitchCase_test.go create mode 100644 internal/fourslash/tests/gen/formatColonAndQMark_test.go create mode 100644 internal/fourslash/tests/gen/formatComments_test.go create mode 100644 internal/fourslash/tests/gen/formatConflictDiff3Marker1_test.go create mode 100644 internal/fourslash/tests/gen/formatConflictMarker1_test.go create mode 100644 internal/fourslash/tests/gen/formatControlFlowConstructs_test.go create mode 100644 internal/fourslash/tests/gen/formatDebuggerStatement_test.go create mode 100644 internal/fourslash/tests/gen/formatDocumentPreserveTrailingWhitespace_test.go create mode 100644 internal/fourslash/tests/gen/formatDocumentWithJSDoc_test.go create mode 100644 internal/fourslash/tests/gen/formatDocumentWithTrivia_test.go create mode 100644 internal/fourslash/tests/gen/formatDotAfterNumber_test.go create mode 100644 internal/fourslash/tests/gen/formatEmptyBlock_test.go create mode 100644 internal/fourslash/tests/gen/formatEmptyParamList_test.go create mode 100644 internal/fourslash/tests/gen/formatExportAssignment_test.go create mode 100644 internal/fourslash/tests/gen/formatIfTryCatchBlocks_test.go create mode 100644 internal/fourslash/tests/gen/formatIfWithEmptyCondition_test.go create mode 100644 internal/fourslash/tests/gen/formatImplicitModule_test.go create mode 100644 internal/fourslash/tests/gen/formatImportDeclaration_test.go create mode 100644 internal/fourslash/tests/gen/formatInTryCatchFinally_test.go create mode 100644 internal/fourslash/tests/gen/formatInTsxFiles_test.go create mode 100644 internal/fourslash/tests/gen/formatInsertSpaceAfterCloseBraceBeforeCloseBracket_test.go create mode 100644 internal/fourslash/tests/gen/formatJsxWithKeywordInIdentifier_test.go create mode 100644 internal/fourslash/tests/gen/formatLiteralTypeInUnionOrIntersectionType_test.go create mode 100644 internal/fourslash/tests/gen/formatMultilineComment_test.go create mode 100644 internal/fourslash/tests/gen/formatMultilineTypesWithMapped_test.go create mode 100644 internal/fourslash/tests/gen/formatMultipleFunctionArguments_test.go create mode 100644 internal/fourslash/tests/gen/formatNestedClassWithOpenBraceOnNewLines_test.go create mode 100644 internal/fourslash/tests/gen/formatNoSpaceAfterTemplateHeadAndMiddle_test.go create mode 100644 internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace1_test.go create mode 100644 internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace2_test.go create mode 100644 internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace3_test.go create mode 100644 internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace4_test.go create mode 100644 internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace5_test.go create mode 100644 internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace6_test.go create mode 100644 internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace_test.go create mode 100644 internal/fourslash/tests/gen/formatNoSpaceBetweenClosingParenAndTemplateString_test.go create mode 100644 internal/fourslash/tests/gen/formatObjectBindingPattern_restElementWithPropertyName_test.go create mode 100644 internal/fourslash/tests/gen/formatObjectBindingPattern_test.go create mode 100644 internal/fourslash/tests/gen/formatOnEnterFunctionDeclaration_test.go create mode 100644 internal/fourslash/tests/gen/formatOnEnterInComment_test.go create mode 100644 internal/fourslash/tests/gen/formatOnEnterOpenBraceAddNewLine_test.go create mode 100644 internal/fourslash/tests/gen/formatOnOpenCurlyBraceRemoveNewLine_test.go create mode 100644 internal/fourslash/tests/gen/formatOnSemiColonAfterBreak_test.go create mode 100644 internal/fourslash/tests/gen/formatParameter_test.go create mode 100644 internal/fourslash/tests/gen/formatRemoveNewLineAfterOpenBrace_test.go create mode 100644 internal/fourslash/tests/gen/formatRemoveSpaceBetweenDotDotDotAndTypeName_test.go create mode 100644 internal/fourslash/tests/gen/formatSatisfiesExpression_test.go create mode 100644 internal/fourslash/tests/gen/formatSpaceAfterImplementsExtends_test.go create mode 100644 internal/fourslash/tests/gen/formatSpaceAfterTemplateHeadAndMiddle_test.go create mode 100644 internal/fourslash/tests/gen/formatSpaceBetweenFunctionAndArrayIndex_test.go create mode 100644 internal/fourslash/tests/gen/formatTSXWithInlineComment_test.go create mode 100644 internal/fourslash/tests/gen/formatTryCatch_test.go create mode 100644 internal/fourslash/tests/gen/formatTryFinally_test.go create mode 100644 internal/fourslash/tests/gen/formatTsxClosingAfterJsxText_test.go create mode 100644 internal/fourslash/tests/gen/formatTsxMultilineAttributeString_test.go create mode 100644 internal/fourslash/tests/gen/formatTsx_test.go create mode 100644 internal/fourslash/tests/gen/formatTypeAnnotation1_test.go create mode 100644 internal/fourslash/tests/gen/formatTypeAnnotation2_test.go create mode 100644 internal/fourslash/tests/gen/formatTypeArgumentOnNewLine_test.go create mode 100644 internal/fourslash/tests/gen/formatTypeParameters_test.go create mode 100644 internal/fourslash/tests/gen/formatVariableDeclarationList_test.go create mode 100644 internal/fourslash/tests/gen/formatWithStatement_test.go create mode 100644 internal/fourslash/tests/gen/formatonkey01_test.go create mode 100644 internal/fourslash/tests/gen/formattingAfterChainedFatArrow_test.go create mode 100644 internal/fourslash/tests/gen/formattingAfterMultiLineIfCondition_test.go create mode 100644 internal/fourslash/tests/gen/formattingAfterMultiLineString_test.go create mode 100644 internal/fourslash/tests/gen/formattingArrayLiteral_test.go create mode 100644 internal/fourslash/tests/gen/formattingAwait_test.go create mode 100644 internal/fourslash/tests/gen/formattingBlockInCaseClauses_test.go create mode 100644 internal/fourslash/tests/gen/formattingChainingMethods_test.go create mode 100644 internal/fourslash/tests/gen/formattingComma_test.go create mode 100644 internal/fourslash/tests/gen/formattingCommentsBeforeErrors_test.go create mode 100644 internal/fourslash/tests/gen/formattingConditionalOperator_test.go create mode 100644 internal/fourslash/tests/gen/formattingConditionalTypes_test.go create mode 100644 internal/fourslash/tests/gen/formattingCrash_test.go create mode 100644 internal/fourslash/tests/gen/formattingDecorators_test.go create mode 100644 internal/fourslash/tests/gen/formattingDoubleLessThan_test.go create mode 100644 internal/fourslash/tests/gen/formattingElseInsideAFunction_test.go create mode 100644 internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go create mode 100644 internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go create mode 100644 internal/fourslash/tests/gen/formattingFatArrowFunctions_test.go create mode 100644 internal/fourslash/tests/gen/formattingForIn_test.go create mode 100644 internal/fourslash/tests/gen/formattingForLoopSemicolons_test.go create mode 100644 internal/fourslash/tests/gen/formattingForOfKeyword_test.go create mode 100644 internal/fourslash/tests/gen/formattingGlobalAugmentation1_test.go create mode 100644 internal/fourslash/tests/gen/formattingGlobalAugmentation2_test.go create mode 100644 internal/fourslash/tests/gen/formattingHexLiteral_test.go create mode 100644 internal/fourslash/tests/gen/formattingIfInElseBlock_test.go create mode 100644 internal/fourslash/tests/gen/formattingIllegalImportClause_test.go create mode 100644 internal/fourslash/tests/gen/formattingInComment_test.go create mode 100644 internal/fourslash/tests/gen/formattingInDestructuring1_test.go create mode 100644 internal/fourslash/tests/gen/formattingInDestructuring2_test.go create mode 100644 internal/fourslash/tests/gen/formattingInDestructuring3_test.go create mode 100644 internal/fourslash/tests/gen/formattingInDestructuring4_test.go create mode 100644 internal/fourslash/tests/gen/formattingInDestructuring5_test.go create mode 100644 internal/fourslash/tests/gen/formattingInExpressionsInTsx_test.go create mode 100644 internal/fourslash/tests/gen/formattingInMultilineComments_test.go create mode 100644 internal/fourslash/tests/gen/formattingJsxTexts1_test.go create mode 100644 internal/fourslash/tests/gen/formattingJsxTexts2_test.go create mode 100644 internal/fourslash/tests/gen/formattingJsxTexts3_test.go create mode 100644 internal/fourslash/tests/gen/formattingJsxTexts4_test.go create mode 100644 internal/fourslash/tests/gen/formattingKeywordAsIdentifier_test.go create mode 100644 internal/fourslash/tests/gen/formattingMappedType_test.go create mode 100644 internal/fourslash/tests/gen/formattingMultilineCommentsWithTabs1_test.go create mode 100644 internal/fourslash/tests/gen/formattingMultilineTemplateLiterals_test.go create mode 100644 internal/fourslash/tests/gen/formattingNestedScopes_test.go create mode 100644 internal/fourslash/tests/gen/formattingNonNullAssertionOperator_test.go create mode 100644 internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlyNewlineAssignment_test.go create mode 100644 internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlyNewlineTyping_test.go create mode 100644 internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlyNewline_test.go create mode 100644 internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlySingleLine_test.go create mode 100644 internal/fourslash/tests/gen/formattingObjectLiteral_test.go create mode 100644 internal/fourslash/tests/gen/formattingOfChainedLambda_test.go create mode 100644 internal/fourslash/tests/gen/formattingOfExportDefault_test.go create mode 100644 internal/fourslash/tests/gen/formattingOfMultilineBlockConstructs_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnChainedCallbacksAndPropertyAccesses_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnClasses_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnCloseBrace_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnClosingBracket_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnCommaOperator_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnConstructorSignature_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnDoWhileNoSemicolon_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnDocumentReadyFunction_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnEmptyInterfaceLiteral_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnEnterInComments_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnEnterInStrings_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnEnter_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnInterfaces_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnInvalidCodes_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnModuleIndentation_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnNestedDoWhileByEnter_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnObjectLiteral_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnOpenBraceOfFunctions_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnSemiColon_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnSingleLineBlocks_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnStatementsWithNoSemicolon_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnTabAfterCloseCurly_test.go create mode 100644 internal/fourslash/tests/gen/formattingOnVariety_test.go create mode 100644 internal/fourslash/tests/gen/formattingQMark_test.go create mode 100644 internal/fourslash/tests/gen/formattingReadonly_test.go create mode 100644 internal/fourslash/tests/gen/formattingRegexes_test.go create mode 100644 internal/fourslash/tests/gen/formattingReplaceTabsWithSpaces_test.go create mode 100644 internal/fourslash/tests/gen/formattingSingleLineWithNewLineOptionSet_test.go create mode 100644 internal/fourslash/tests/gen/formattingSkippedTokens_test.go create mode 100644 internal/fourslash/tests/gen/formattingSpaceAfterCommaBeforeOpenParen_test.go create mode 100644 internal/fourslash/tests/gen/formattingSpaceBeforeCloseParen_test.go create mode 100644 internal/fourslash/tests/gen/formattingSpaceBeforeFunctionParen_test.go create mode 100644 internal/fourslash/tests/gen/formattingSpaceBetweenOptionalChaining_test.go create mode 100644 internal/fourslash/tests/gen/formattingSpaceBetweenParent_test.go create mode 100644 internal/fourslash/tests/gen/formattingSpacesAfterConstructor_test.go create mode 100644 internal/fourslash/tests/gen/formattingTemplatesWithNewline_test.go create mode 100644 internal/fourslash/tests/gen/formattingTemplates_test.go create mode 100644 internal/fourslash/tests/gen/formattingTypeInfer_test.go create mode 100644 internal/fourslash/tests/gen/formattingVoid_test.go create mode 100644 internal/fourslash/tests/gen/formattingWithMultilineComments_test.go create mode 100644 internal/fourslash/tests/gen/formattingofSingleLineBlockConstructs_test.go create mode 100644 internal/fourslash/tests/gen/functionFormatting_test.go create mode 100644 internal/fourslash/tests/gen/functionIndentation_test.go create mode 100644 internal/fourslash/tests/gen/functionTypeFormatting_test.go create mode 100644 internal/fourslash/tests/gen/functionTypePredicateFormatting_test.go create mode 100644 internal/fourslash/tests/gen/generatorDeclarationFormatting_test.go create mode 100644 internal/fourslash/tests/gen/genericsFormattingMultiline_test.go create mode 100644 internal/fourslash/tests/gen/genericsFormatting_test.go create mode 100644 internal/fourslash/tests/gen/importNameCodeFix_externalNonRelateive2_test.go create mode 100644 internal/fourslash/tests/gen/importNameCodeFix_externalNonRelative1_test.go create mode 100644 internal/fourslash/tests/gen/importTypeFormatting_test.go create mode 100644 internal/fourslash/tests/gen/indentAfterFunctionClosingBraces_test.go create mode 100644 internal/fourslash/tests/gen/indentationInJsx3_test.go create mode 100644 internal/fourslash/tests/gen/multilineCommentBeforeOpenBrace_test.go create mode 100644 internal/fourslash/tests/gen/optionalPropertyFormatting_test.go create mode 100644 internal/fourslash/tests/gen/paste_test.go create mode 100644 internal/fourslash/tests/gen/semicolonFormattingAfterArrayLiteral_test.go create mode 100644 internal/fourslash/tests/gen/semicolonFormattingInsideAComment_test.go create mode 100644 internal/fourslash/tests/gen/semicolonFormattingInsideAStringLiteral_test.go create mode 100644 internal/fourslash/tests/gen/semicolonFormattingNestedStatements_test.go create mode 100644 internal/fourslash/tests/gen/semicolonFormatting_test.go create mode 100644 internal/fourslash/tests/gen/singleLineTypeLiteralFormatting_test.go create mode 100644 internal/fourslash/tests/gen/smartIndentNamedImport_test.go create mode 100644 internal/fourslash/tests/gen/spaceAfterConstructor_test.go create mode 100644 internal/fourslash/tests/gen/spaceAfterReturn_test.go create mode 100644 internal/fourslash/tests/gen/spaceAfterStatementConditions_test.go create mode 100644 internal/fourslash/tests/gen/spaceBeforeAndAfterBinaryOperators_test.go create mode 100644 internal/fourslash/tests/gen/tabbingAfterNewlineInsertedBeforeWhile_test.go create mode 100644 internal/fourslash/tests/gen/typeAssertionsFormatting_test.go create mode 100644 internal/fourslash/tests/gen/unclosedStringLiteralAutoformating_test.go create mode 100644 internal/fourslash/tests/gen/whiteSpaceBeforeReturnTypeFormatting_test.go create mode 100644 internal/fourslash/tests/gen/whiteSpaceTrimming2_test.go create mode 100644 internal/fourslash/tests/gen/whiteSpaceTrimming3_test.go create mode 100644 internal/fourslash/tests/gen/whiteSpaceTrimming4_test.go create mode 100644 internal/fourslash/tests/gen/whiteSpaceTrimming_test.go create mode 100644 testdata/baselines/reference/submodule/compiler/arrowFunctionErrorSpan.errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/compiler/asyncFunctionNoReturnType.errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/compiler/contextualTupleTypeParameterReadonly.errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/compiler/noImplicitReturnsExclusions.errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/compiler/recursiveTypeRelations.errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/compiler/undeclaredModuleError.errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/conformance/importCallExpressionNoModuleKindSpecified.errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=es5).errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=esnext).errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=es5).errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=esnext).errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=es5).errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=esnext).errors.txt.diff diff --git a/internal/format/span.go b/internal/format/span.go index 018077f770..1a8f3ff972 100644 --- a/internal/format/span.go +++ b/internal/format/span.go @@ -268,7 +268,7 @@ func (w *formatSpanWorker) execute(s *formattingScanner) []core.TextChange { w.insertIndentation(item.Loc.Pos(), indentation, false) }) - if opt.TrimTrailingWhitespace != false { + if opt.TrimTrailingWhitespace { w.trimTrailingWhitespacesForRemainingRange(remainingTrivia) } } @@ -303,6 +303,9 @@ func (w *formatSpanWorker) execute(s *formattingScanner) []core.TextChange { // edit in the middle of a token where the range ended, so if we have a non-contiguous // pair here, we're already done and we can ignore it. parent := astnav.FindPrecedingToken(w.sourceFile, tokenInfo.Loc.End()) + if parent != nil { + parent = parent.Parent + } if parent == nil { parent = w.previousParent } diff --git a/internal/fourslash/_scripts/convertFourslash.mts b/internal/fourslash/_scripts/convertFourslash.mts index c8e1d679bf..9777d2236a 100644 --- a/internal/fourslash/_scripts/convertFourslash.mts +++ b/internal/fourslash/_scripts/convertFourslash.mts @@ -179,6 +179,12 @@ function parseFourslashStatement(statement: ts.Statement): Cmd[] | undefined { case "importFixAtPosition": // `verify.importFixAtPosition(...)` return parseImportFixAtPositionArgs(callExpression.arguments); + case "currentLineContentIs": + case "currentFileContentIs": + case "indentationIs": + case "indentationAtPositionIs": + case "textAtCaretIs": + return parseCurrentContentIsArgs(func.text, callExpression.arguments); case "quickInfoAt": case "quickInfoExists": case "quickInfoIs": @@ -251,6 +257,9 @@ function parseFourslashStatement(statement: ts.Statement): Cmd[] | undefined { } return [result]; } + if (namespace.text === "format") { + return parseFormatStatement(func.text, callExpression.arguments); + } // !!! other fourslash commands } console.error(`Unrecognized fourslash statement: ${statement.getText()}`); @@ -307,6 +316,63 @@ function parseEditStatement(funcName: string, args: readonly ts.Expression[]): E } } +function parseFormatStatement(funcName: string, args: readonly ts.Expression[]): FormatCmd[] | undefined { + switch (funcName) { + case "document": { + return [{ + kind: "format", + goStatement: `f.FormatDocument(t, "")`, + }]; + } + case "setOption": + const optName = getGoStringLiteral(getStringLiteralLike(args[0])!.text); + return [{ + kind: "format", + goStatement: `f.SetFormatOption(t, ${optName}, ${args[1].getText()})`, + }]; + case "selection": + case "onType": + case "copyFormatOptions": + case "setFormatOptions": + console.error(`format function not implemented: ${funcName}`); + break; + default: + console.error(`Unrecognized format function: ${funcName}`); + } + return undefined; +} + +function parseCurrentContentIsArgs(funcName: string, args: readonly ts.Expression[]): VerifyContentCmd[] | undefined { + switch (funcName) { + case "currentFileContentIs": + return [{ + kind: "verifyContent", + goStatement: `f.VerifyCurrentFileContent(t, ${getGoStringLiteralFromNode(args[0])!})`, + }]; + case "currentLineContentIs": + return [{ + kind: "verifyContent", + goStatement: `f.VerifyCurrentLineContent(t, ${getGoStringLiteralFromNode(args[0])!})`, + }]; + case "indentationIs": + // return [{ + // kind: "verifyContent", + // goStatement: `f.VerifyIndentation(t, ${getNumericLiteral(args[0])?.text})`, + // }]; + case "indentationAtPositionIs": + case "textAtCaretIs": + console.error(`unimplemented verify content function: ${funcName}`); + return undefined; + // return [{ + // kind: "verifyContent", + // goStatement: `f.VerifyTextAtCaret(t, ${getGoStringLiteral(args[0].getText())})`, + // }]; + default: + console.error(`Unrecognized verify content function: ${funcName}`); + return undefined; + } +} + function getGoMultiLineStringLiteral(text: string): string { if (!text.includes("`") && !text.includes("\\")) { return "`" + text + "`"; @@ -318,6 +384,24 @@ function getGoStringLiteral(text: string): string { return `${JSON.stringify(text)}`; } +function getGoStringLiteralFromNode(node: ts.Node): string | undefined { + const stringLiteralLike = getStringLiteralLike(node); + if (stringLiteralLike) { + return getGoMultiLineStringLiteral(stringLiteralLike.text); + } + switch (node.kind) { + case ts.SyntaxKind.BinaryExpression: { + const binaryExpr = node as ts.BinaryExpression; + const left = getGoStringLiteralFromNode(binaryExpr.left); + const right = getGoStringLiteralFromNode(binaryExpr.right); + const op = binaryExpr.operatorToken.getText(); + return left + op + right; + } + default: + console.error(`Unhandled case ${node.kind} in getGoStringLiteralFromNode: ${node.getText()}`); + } +} + function parseGoToArgs(args: readonly ts.Expression[], funcName: string): GoToCmd[] | undefined { switch (funcName) { case "marker": { @@ -2498,6 +2582,16 @@ interface EditCmd { goStatement: string; } +interface FormatCmd { + kind: "format"; // | "formatSelection" | "formatOnType" | "copyFormatOptions" | "setFormatOptions" | "setOption"; + goStatement: string; +} + +interface VerifyContentCmd { + kind: "verifyContent"; + goStatement: string; +} + interface VerifyQuickInfoCmd { kind: "quickInfoIs" | "quickInfoAt" | "quickInfoExists" | "notQuickInfoExists"; marker?: string; @@ -2582,7 +2676,9 @@ type Cmd = | VerifyNoSignatureHelpForTriggerReasonCmd | VerifyBaselineCallHierarchy | GoToCmd + | FormatCmd | EditCmd + | VerifyContentCmd | VerifyQuickInfoCmd | VerifyBaselineRenameCmd | VerifyRenameInfoCmd @@ -2860,6 +2956,8 @@ function generateCmd(cmd: Cmd): string { case "goTo": return generateGoToCommand(cmd); case "edit": + case "format": + case "verifyContent": return cmd.goStatement; case "quickInfoAt": case "quickInfoIs": diff --git a/internal/fourslash/_scripts/failingTests.txt b/internal/fourslash/_scripts/failingTests.txt index d9ed2dcb55..1e314e5c37 100644 --- a/internal/fourslash/_scripts/failingTests.txt +++ b/internal/fourslash/_scripts/failingTests.txt @@ -3,6 +3,7 @@ TestAmbientShorthandGotoDefinition TestArgumentsAreAvailableAfterEditsAtEndOfFunction TestAugmentedTypesClass1 TestAugmentedTypesClass3Fourslash +TestAutoFormattingOnPasting TestAutoImportCompletionAmbientMergedModule1 TestAutoImportCompletionExportListAugmentation1 TestAutoImportCompletionExportListAugmentation2 @@ -32,7 +33,10 @@ TestAutoImportProvider_pnpm TestAutoImportProvider_wildcardExports1 TestAutoImportProvider_wildcardExports2 TestAutoImportProvider_wildcardExports3 +TestAutoImportProvider1 TestAutoImportProvider4 +TestAutoImportProvider7 +TestAutoImportProvider8 TestAutoImportSortCaseSensitivity1 TestAutoImportSymlinkCaseSensitive TestAutoImportTypeImport1 @@ -241,10 +245,87 @@ TestExportDefaultClass TestExportDefaultFunction TestFindReferencesBindingPatternInJsdocNoCrash1 TestFindReferencesBindingPatternInJsdocNoCrash2 +TestForceIndentAfterNewLineInsert +TestFormat01 +TestFormatAfterObjectLiteral +TestFormatArrayLiteralExpression +TestFormatAsyncClassMethod1 +TestFormatAsyncClassMethod2 +TestFormatColonAndQMark +TestFormatComments +TestFormatConflictDiff3Marker1 +TestFormatConflictMarker1 +TestFormatDebuggerStatement +TestFormatDocumentPreserveTrailingWhitespace +TestFormatDocumentWithJSDoc +TestFormatDocumentWithTrivia +TestFormatDotAfterNumber +TestFormatEmptyParamList +TestFormatIfTryCatchBlocks +TestFormatIfWithEmptyCondition +TestFormatImplicitModule +TestFormatMultipleFunctionArguments +TestFormatNoSpaceAfterTemplateHeadAndMiddle +TestFormatObjectBindingPattern +TestFormatOnSemiColonAfterBreak +TestFormatRemoveNewLineAfterOpenBrace +TestFormatSpaceAfterImplementsExtends +TestFormatSpaceAfterTemplateHeadAndMiddle +TestFormatSpaceBetweenFunctionAndArrayIndex +TestFormattingAfterMultiLineIfCondition +TestFormattingAwait +TestFormattingChainingMethods +TestFormattingDecorators +TestFormattingDoubleLessThan +TestFormattingForIn +TestFormattingForLoopSemicolons +TestFormattingForOfKeyword +TestFormattingGlobalAugmentation2 +TestFormattingInExpressionsInTsx +TestFormattingJsxTexts2 +TestFormattingJsxTexts3 +TestFormattingJsxTexts4 +TestFormattingMappedType +TestFormattingMultilineCommentsWithTabs1 +TestFormattingNestedScopes +TestFormattingNonNullAssertionOperator +TestFormattingObjectLiteral +TestFormattingObjectLiteralOpenCurlyNewline +TestFormattingObjectLiteralOpenCurlyNewlineAssignment +TestFormattingObjectLiteralOpenCurlyNewlineTyping +TestFormattingObjectLiteralOpenCurlySingleLine +TestFormattingOfExportDefault +TestFormattingOnClasses +TestFormattingOnClosingBracket +TestFormattingOnDocumentReadyFunction +TestFormattingOnDoWhileNoSemicolon +TestFormattingOnEmptyInterfaceLiteral +TestFormattingOnInvalidCodes +TestFormattingOnModuleIndentation +TestFormattingOnNestedDoWhileByEnter +TestFormattingOnObjectLiteral +TestFormattingOnSingleLineBlocks +TestFormattingOnStatementsWithNoSemicolon +TestFormattingOnTabAfterCloseCurly +TestFormattingOnVariety +TestFormattingReplaceTabsWithSpaces +TestFormattingSpaceAfterCommaBeforeOpenParen +TestFormattingSpaceBeforeFunctionParen +TestFormattingSpaceBetweenParent +TestFormattingSpacesAfterConstructor +TestFormattingTemplates +TestFormattingVoid +TestFormatTryFinally +TestFormatTsxClosingAfterJsxText +TestFormatVariableDeclarationList +TestFormatWithStatement +TestFunctionIndentation +TestFunctionTypePredicateFormatting TestGenericCombinators3 TestGenericCombinatorWithConstraints1 TestGenericFunctionWithGenericParams1 TestGenericInterfacesWithConstraints1 +TestGenericsFormattingMultiline TestGenericTypeWithMultipleBases1MultiFile TestGetJavaScriptCompletions10 TestGetJavaScriptCompletions12 @@ -285,6 +366,8 @@ TestImportCompletionsPackageJsonImportsPattern_ts_ts TestImportCompletionsPackageJsonImportsPattern2 TestImportFixesGlobalTypingsCache TestImportNameCodeFix_avoidRelativeNodeModules +TestImportNameCodeFix_externalNonRelateive2 +TestImportNameCodeFix_externalNonRelative1 TestImportNameCodeFix_fileWithNoTrailingNewline TestImportNameCodeFix_HeaderComment1 TestImportNameCodeFix_HeaderComment2 @@ -329,6 +412,7 @@ TestImportTypeCompletions6 TestImportTypeCompletions7 TestImportTypeCompletions8 TestImportTypeCompletions9 +TestIndentationInJsx3 TestIndexerReturnTypes1 TestIndirectClassInstantiation TestInstanceTypesForGenericType1 @@ -378,11 +462,13 @@ TestMemberListOfExportedClass TestMemberListOnContextualThis TestModuleNodeNextAutoImport2 TestModuleNodeNextAutoImport3 +TestMultilineCommentBeforeOpenBrace TestNgProxy1 TestNodeModulesImportCompletions1 TestNoQuickInfoForLabel TestNoQuickInfoInWhitespace TestNumericPropertyNames +TestOptionalPropertyFormatting TestOverloadQuickInfo TestParameterWithDestructuring TestParameterWithNestedDestructuring @@ -550,11 +636,14 @@ TestRenameFromNodeModulesDep4 TestRenamePrivateFields TestReverseMappedTypeQuickInfo TestSelfReferencedExternalModule +TestSemicolonFormattingNestedStatements +TestSpaceAfterReturn TestStringCompletionsImportOrExportSpecifier TestStringCompletionsVsEscaping TestSymbolCompletionLowerPriority TestSyntheticImportFromBabelGeneratedFile1 TestSyntheticImportFromBabelGeneratedFile2 +TestTabbingAfterNewlineInsertedBeforeWhile TestThisBindingInLambda TestThisPredicateFunctionQuickInfo01 TestThisPredicateFunctionQuickInfo02 @@ -571,3 +660,7 @@ TestTsxQuickInfo5 TestTsxQuickInfo6 TestTsxQuickInfo7 TestTypeOperatorNodeBuilding +TestUnclosedStringLiteralAutoformating +TestWhiteSpaceTrimming +TestWhiteSpaceTrimming2 +TestWhiteSpaceTrimming4 diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index b9e223b88d..5449c26650 100644 --- a/internal/fourslash/fourslash.go +++ b/internal/fourslash/fourslash.go @@ -58,11 +58,13 @@ type FourslashTest struct { scriptInfos map[string]*scriptInfo converters *lsconv.Converters - userPreferences *lsutil.UserPreferences - currentCaretPosition lsproto.Position - lastKnownMarkerName *string - activeFilename string - selectionEnd *lsproto.Position + stateEnableFormatting bool + reportFormatOnTypeCrash bool + userPreferences *lsutil.UserPreferences + currentCaretPosition lsproto.Position + lastKnownMarkerName *string + activeFilename string + selectionEnd *lsproto.Position isStradaServer bool // Whether this is a fourslash server test in Strada. !!! Remove once we don't need to diff baselines. @@ -101,6 +103,27 @@ func (s *scriptInfo) FileName() string { return s.fileName } +func (s *scriptInfo) GetLineContent(line int) string { + numLines := len(s.lineMap.LineStarts) + if line < 0 || line >= numLines { + return "" + } + start := s.lineMap.LineStarts[line] + var end core.TextPos + if line+1 < numLines { + end = s.lineMap.LineStarts[line+1] + } else { + end = core.TextPos(len(s.content)) + } + + // delete trailing newline + content := s.content[start:end] + if len(content) > 0 && content[len(content)-1] == '\n' { + content = content[:len(content)-1] + } + return content +} + type lspReader struct { c <-chan *lsproto.Message } @@ -228,17 +251,19 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten }) f := &FourslashTest{ - server: server, - in: inputWriter, - out: outputReader, - testData: &testData, - userPreferences: lsutil.NewDefaultUserPreferences(), // !!! parse default preferences for fourslash case? - vfs: fs, - scriptInfos: scriptInfos, - converters: converters, - baselines: make(map[baselineCommand]*strings.Builder), - openFiles: make(map[string]struct{}), - pendingRequests: make(map[lsproto.ID]chan *lsproto.ResponseMessage), + server: server, + in: inputWriter, + out: outputReader, + testData: &testData, + stateEnableFormatting: true, + reportFormatOnTypeCrash: true, + userPreferences: lsutil.NewDefaultUserPreferences(), // !!! parse default preferences for fourslash case? + vfs: fs, + scriptInfos: scriptInfos, + converters: converters, + baselines: make(map[baselineCommand]*strings.Builder), + openFiles: make(map[string]struct{}), + pendingRequests: make(map[lsproto.ID]chan *lsproto.ResponseMessage), } ctx, cancel := context.WithCancel(t.Context()) @@ -599,17 +624,25 @@ func (f *FourslashTest) writeMsg(t *testing.T, msg *lsproto.Message) { } func sendRequest[Params, Resp any](t *testing.T, f *FourslashTest, info lsproto.RequestInfo[Params, Resp], params Params) Resp { - t.Helper() + // t.Helper() prefix := f.getCurrentPositionPrefix() f.baselineState(t) f.baselineRequestOrNotification(t, info.Method, params) resMsg, result, resultOk := sendRequestWorker(t, f, info, params) f.baselineState(t) - if resMsg == nil { - t.Fatalf(prefix+"Nil response received for %s request", info.Method) - } - if !resultOk { - t.Fatalf(prefix+"Unexpected %s response type: %T", info.Method, resMsg.AsResponse().Result) + switch info.Method { + case lsproto.MethodTextDocumentOnTypeFormatting: + if !f.reportFormatOnTypeCrash { + break + } + fallthrough + default: + if resMsg == nil { + t.Fatalf(prefix+"Nil response received for %s request", info.Method) + } + if !resultOk { + t.Fatalf(prefix+"Unexpected %s response type: %T", info.Method, resMsg.AsResponse().Result) + } } return result } @@ -631,6 +664,13 @@ func (f *FourslashTest) updateState(method lsproto.Method, params any) { } } +func (f *FourslashTest) SetFormatOption(t *testing.T, optionName string, value any) { + t.Helper() + newPreferences := f.userPreferences.Copy() + newPreferences.Set(optionName, value) + f.Configure(t, newPreferences) +} + func (f *FourslashTest) Configure(t *testing.T, config *lsutil.UserPreferences) { // !!! // Callers to this function may need to consider @@ -844,6 +884,47 @@ func (f *FourslashTest) openFile(t *testing.T, filename string) { f.baselineProjectsAfterNotification(t, filename) } +func (f *FourslashTest) FormatDocument(t *testing.T, filename string) { + if filename == "" { + filename = f.activeFilename + } + result := sendRequest(t, f, lsproto.TextDocumentFormattingInfo, &lsproto.DocumentFormattingParams{ + TextDocument: lsproto.TextDocumentIdentifier{ + Uri: lsconv.FileNameToDocumentURI(filename), + }, + Options: f.userPreferences.FormatCodeSettings.ToLSFormatOptions(), + }) + if result.TextEdits == nil { + return + } + f.applyTextEdits(t, *result.TextEdits) +} + +func (f *FourslashTest) VerifyCurrentFileContent(t *testing.T, expectedContent string) { + t.Helper() + actualContent := f.getScriptInfo(f.activeFilename).content + assert.Equal(t, actualContent, expectedContent) +} + +func (f *FourslashTest) VerifyCurrentLineContent(t *testing.T, expectedContent string) { + t.Helper() + actualContent := f.getScriptInfo(f.activeFilename).GetLineContent(int(f.currentCaretPosition.Line)) + assert.Equal(t, actualContent, expectedContent, fmt.Sprintf(` + actual line: "%s" +expected line: "%s" +`, + actualContent, + expectedContent, + )) +} + +func (f *FourslashTest) VerifyIndentation(t *testing.T, numSpaces int) { + t.Helper() + // not implemented + // actualContent := f.getScriptInfo(f.activeFilename).GetLineContent(int(f.currentCaretPosition.Line)) + // assert.Equal(t, actualContent, expectedContent, fmt.Sprintf("Actual line content %s does not match expected content.", actualContent)) +} + func getLanguageKind(filename string) lsproto.LanguageKind { if tspath.FileExtensionIsOneOf( filename, @@ -1337,13 +1418,14 @@ func (f *FourslashTest) VerifyImportFixAtPosition(t *testing.T, expectedTexts [] diagnostics = diagResult.FullDocumentDiagnosticReport.Items } + currentCaretPosition := f.currentCaretPosition params := &lsproto.CodeActionParams{ TextDocument: lsproto.TextDocumentIdentifier{ Uri: lsconv.FileNameToDocumentURI(f.activeFilename), }, Range: lsproto.Range{ - Start: f.currentCaretPosition, - End: f.currentCaretPosition, + End: currentCaretPosition, + Start: currentCaretPosition, }, Context: &lsproto.CodeActionContext{ Diagnostics: diagnostics, @@ -1407,6 +1489,7 @@ func (f *FourslashTest) VerifyImportFixAtPosition(t *testing.T, expectedTexts [] insertedText := textChange.NewText f.editScriptAndUpdateMarkers(t, f.activeFilename, start, start+len(insertedText), deletedText) } + f.currentCaretPosition = currentCaretPosition } // Compare results @@ -1422,9 +1505,7 @@ func (f *FourslashTest) VerifyImportFixAtPosition(t *testing.T, expectedTexts [] } for i, expected := range expectedTexts { actual := actualTextArray[i] - if expected != actual { - t.Fatalf("Import fix at index %d doesn't match.\nExpected:\n%s\n\nActual:\n%s", i, expected, actual) - } + assert.Equal(t, expected, actual, fmt.Sprintf("Import fix at index %d doesn't match.\n", i)) } } @@ -2406,11 +2487,13 @@ func roundtripThroughJson[T any](value any) (T, error) { // Insert text at the current caret position. func (f *FourslashTest) Insert(t *testing.T, text string) { + t.Helper() f.typeText(t, text) } // Insert text and a new line at the current caret position. func (f *FourslashTest) InsertLine(t *testing.T, text string) { + t.Helper() f.typeText(t, text+"\n") } @@ -2434,6 +2517,23 @@ func (f *FourslashTest) Paste(t *testing.T, text string) { script := f.getScriptInfo(f.activeFilename) start := int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)) f.editScriptAndUpdateMarkers(t, f.activeFilename, start, start, text) + + // post-paste fomatting + if f.stateEnableFormatting { + result := sendRequest(t, f, lsproto.TextDocumentRangeFormattingInfo, &lsproto.DocumentRangeFormattingParams{ + TextDocument: lsproto.TextDocumentIdentifier{ + Uri: lsconv.FileNameToDocumentURI(f.activeFilename), + }, + Range: lsproto.Range{ + Start: f.currentCaretPosition, + End: f.converters.PositionToLineAndCharacter(script, core.TextPos(start+len(text))), + }, + Options: f.userPreferences.FormatCodeSettings.ToLSFormatOptions(), + }) + if result.TextEdits != nil { + f.applyTextEdits(t, *result.TextEdits) + } + } // this.checkPostEditInvariants(); // !!! do we need this? } @@ -2477,20 +2577,38 @@ func (f *FourslashTest) getSelection() core.TextRange { ) } -func (f *FourslashTest) applyTextEdits(t *testing.T, edits []*lsproto.TextEdit) { +// Updates f.currentCaretPosition +func (f *FourslashTest) applyTextEdits(t *testing.T, edits []*lsproto.TextEdit) int { script := f.getScriptInfo(f.activeFilename) slices.SortFunc(edits, func(a, b *lsproto.TextEdit) int { aStart := f.converters.LineAndCharacterToPosition(script, a.Range.Start) bStart := f.converters.LineAndCharacterToPosition(script, b.Range.Start) return int(aStart) - int(bStart) }) + + totalOffset := 0 + currentCaretPosition := int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)) // Apply edits in reverse order to avoid affecting the positions of earlier edits. for i := len(edits) - 1; i >= 0; i-- { edit := edits[i] start := int(f.converters.LineAndCharacterToPosition(script, edit.Range.Start)) end := int(f.converters.LineAndCharacterToPosition(script, edit.Range.End)) f.editScriptAndUpdateMarkers(t, f.activeFilename, start, end, edit.NewText) + + delta := len(edit.NewText) - (end - start) + if start <= currentCaretPosition { + if end <= currentCaretPosition { + // The entirety of the edit span falls before the caret position, shift the caret accordingly + currentCaretPosition += delta + } else { + // The span being replaced includes the caret position, place the caret at the beginning of the span + currentCaretPosition = start + } + } + totalOffset += delta } + f.currentCaretPosition = f.converters.PositionToLineAndCharacter(script, core.TextPos(currentCaretPosition)) + return totalOffset } func (f *FourslashTest) Replace(t *testing.T, start int, length int, text string) { @@ -2500,29 +2618,41 @@ func (f *FourslashTest) Replace(t *testing.T, start int, length int, text string // Inserts the text currently at the caret position character by character, as if the user typed it. func (f *FourslashTest) typeText(t *testing.T, text string) { + // temprorary -- this disables tests failing if format crashes; this unblocks unrelated tests such as codefixes + f.reportFormatOnTypeCrash = false + defer func() { + f.reportFormatOnTypeCrash = true + }() + script := f.getScriptInfo(f.activeFilename) - offset := int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)) selection := f.getSelection() f.Replace(t, selection.Pos(), selection.End()-selection.Pos(), "") totalSize := 0 + offset := int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)) for totalSize < len(text) { r, size := utf8.DecodeRuneInString(text[totalSize:]) - f.editScriptAndUpdateMarkers(t, f.activeFilename, totalSize+offset, totalSize+offset, string(r)) + f.editScriptAndUpdateMarkers(t, f.activeFilename, offset, offset, string(r)) totalSize += size - f.currentCaretPosition = f.converters.PositionToLineAndCharacter(script, core.TextPos(totalSize+offset)) + offset += size + f.currentCaretPosition = f.converters.PositionToLineAndCharacter(script, core.TextPos(offset)) - // !!! formatting // Handle post-keystroke formatting - // if this.enableFormatting { - // const edits = this.languageService.getFormattingEditsAfterKeystroke(this.activeFile.fileName, offset, ch, this.formatCodeSettings) - // if edits.length { - // offset += this.applyEdits(this.activeFile.fileName, edits) - // } - // } - + if f.stateEnableFormatting { + result := sendRequest(t, f, lsproto.TextDocumentOnTypeFormattingInfo, &lsproto.DocumentOnTypeFormattingParams{ + TextDocument: lsproto.TextDocumentIdentifier{ + Uri: lsconv.FileNameToDocumentURI(f.activeFilename), + }, + Position: f.currentCaretPosition, + Ch: string(r), + Options: f.userPreferences.FormatCodeSettings.ToLSFormatOptions(), + }) + if result.TextEdits != nil { + offset += f.applyTextEdits(t, *result.TextEdits) + } + } } // f.checkPostEditInvariants() // !!! do we need this? diff --git a/internal/fourslash/tests/gen/asOperatorFormatting_test.go b/internal/fourslash/tests/gen/asOperatorFormatting_test.go new file mode 100644 index 0000000000..f6cb9dce88 --- /dev/null +++ b/internal/fourslash/tests/gen/asOperatorFormatting_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAsOperatorFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/var x = 3 as number;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.FormatDocument(t, "") + f.VerifyCurrentLineContent(t, `var x = 3 as number;`) +} diff --git a/internal/fourslash/tests/gen/autoFormattingOnPasting_test.go b/internal/fourslash/tests/gen/autoFormattingOnPasting_test.go new file mode 100644 index 0000000000..31c2734687 --- /dev/null +++ b/internal/fourslash/tests/gen/autoFormattingOnPasting_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAutoFormattingOnPasting(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module TestModule { +/**/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Paste(t, " class TestClass{\nprivate foo;\npublic testMethod( )\n{}\n}") + f.VerifyCurrentFileContent(t, `module TestModule { + class TestClass { + private foo; + public testMethod() { } + } +}`) +} diff --git a/internal/fourslash/tests/gen/autoImportProvider1_test.go b/internal/fourslash/tests/gen/autoImportProvider1_test.go new file mode 100644 index 0000000000..4df8d5edbc --- /dev/null +++ b/internal/fourslash/tests/gen/autoImportProvider1_test.go @@ -0,0 +1,34 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAutoImportProvider1(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/node_modules/@angular/forms/package.json +{ "name": "@angular/forms", "typings": "./forms.d.ts" } +// @Filename: /home/src/workspaces/project/node_modules/@angular/forms/forms.d.ts +export class PatternValidator {} +// @Filename: /home/src/workspaces/project/tsconfig.json +{} +// @Filename: /home/src/workspaces/project/package.json +{ "dependencies": { "@angular/forms": "*" } } +// @Filename: /home/src/workspaces/project/index.ts +PatternValidator/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.GoToMarker(t, "") + f.SetFormatOption(t, "newLineCharacter", "\n") + f.VerifyImportFixAtPosition(t, []string{ + `import { PatternValidator } from "@angular/forms"; + +PatternValidator`, + }, nil /*preferences*/) +} diff --git a/internal/fourslash/tests/gen/autoImportProvider2_test.go b/internal/fourslash/tests/gen/autoImportProvider2_test.go new file mode 100644 index 0000000000..cb9ce40c11 --- /dev/null +++ b/internal/fourslash/tests/gen/autoImportProvider2_test.go @@ -0,0 +1,35 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAutoImportProvider2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/node_modules/direct-dependency/package.json +{ "name": "direct-dependency", "dependencies": { "indirect-dependency": "*" } } +// @Filename: /home/src/workspaces/project/node_modules/direct-dependency/index.d.ts +import "indirect-dependency"; +export declare class DirectDependency {} +// @Filename: /home/src/workspaces/project/node_modules/indirect-dependency/package.json +{ "name": "indirect-dependency" } +// @Filename: /home/src/workspaces/project/node_modules/indirect-dependency/index.d.ts +export declare class IndirectDependency +// @Filename: /home/src/workspaces/project/tsconfig.json +{} +// @Filename: /home/src/workspaces/project/package.json +{ "dependencies": { "direct-dependency": "*" } } +// @Filename: /home/src/workspaces/project/index.ts +IndirectDependency/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.GoToMarker(t, "") + f.SetFormatOption(t, "newLineCharacter", "\n") + f.VerifyImportFixAtPosition(t, []string{}, nil /*preferences*/) +} diff --git a/internal/fourslash/tests/gen/autoImportProvider7_test.go b/internal/fourslash/tests/gen/autoImportProvider7_test.go new file mode 100644 index 0000000000..b81b702e24 --- /dev/null +++ b/internal/fourslash/tests/gen/autoImportProvider7_test.go @@ -0,0 +1,76 @@ +package fourslash_test + +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/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAutoImportProvider7(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/tsconfig.json +{ "compilerOptions": { "module": "commonjs" } } +// @Filename: /home/src/workspaces/project/package.json +{ "dependencies": { "mylib": "file:packages/mylib" } } +// @Filename: /home/src/workspaces/project/packages/mylib/package.json +{ "name": "mylib", "version": "1.0.0", "main": "index.js", "types": "index" } +// @Filename: /home/src/workspaces/project/packages/mylib/index.ts +export * from "./mySubDir"; +// @Filename: /home/src/workspaces/project/packages/mylib/mySubDir/index.ts +export * from "./myClass"; +export * from "./myClass2"; +// @Filename: /home/src/workspaces/project/packages/mylib/mySubDir/myClass.ts +export class MyClass {} +// @Filename: /home/src/workspaces/project/packages/mylib/mySubDir/myClass2.ts +export class MyClass2 {} +// @link: /home/src/workspaces/project/packages/mylib -> /home/src/workspaces/project/node_modules/mylib +// @Filename: /home/src/workspaces/project/src/index.ts + +const a = new MyClass/*1*/(); +const b = new MyClass2/*2*/();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.GoToMarker(t, "1") + f.SetFormatOption(t, "newLineCharacter", "\n") + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "MyClass", + Data: &lsproto.CompletionItemData{ + AutoImport: &lsproto.AutoImportData{ + ModuleSpecifier: "mylib", + }, + }, + AdditionalTextEdits: fourslash.AnyTextEdits, + SortText: PtrTo(string(ls.SortTextAutoImportSuggestions)), + }, + }, + }, + }) + f.VerifyApplyCodeActionFromCompletion(t, PtrTo("1"), &fourslash.ApplyCodeActionFromCompletionOptions{ + Name: "MyClass", + Source: "mylib", + Description: "Add import from \"mylib\"", + AutoImportData: &lsproto.AutoImportData{ + ExportName: "MyClass", + FileName: "/home/src/workspaces/project/packages/mylib/index.ts", + }, + NewFileContent: PtrTo(`import { MyClass } from "mylib"; + +const a = new MyClass(); +const b = new MyClass2();`), + }) +} diff --git a/internal/fourslash/tests/gen/autoImportProvider8_test.go b/internal/fourslash/tests/gen/autoImportProvider8_test.go new file mode 100644 index 0000000000..5339ac91d1 --- /dev/null +++ b/internal/fourslash/tests/gen/autoImportProvider8_test.go @@ -0,0 +1,76 @@ +package fourslash_test + +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/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAutoImportProvider8(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/tsconfig.json +{ "compilerOptions": { "module": "commonjs" } } +// @Filename: /home/src/workspaces/project/package.json +{ "dependencies": { "mylib": "file:packages/mylib" } } +// @Filename: /home/src/workspaces/project/packages/mylib/package.json +{ "name": "mylib", "version": "1.0.0" } +// @Filename: /home/src/workspaces/project/packages/mylib/index.ts +export * from "./mySubDir"; +// @Filename: /home/src/workspaces/project/packages/mylib/mySubDir/index.ts +export * from "./myClass"; +export * from "./myClass2"; +// @Filename: /home/src/workspaces/project/packages/mylib/mySubDir/myClass.ts +export class MyClass {} +// @Filename: /home/src/workspaces/project/packages/mylib/mySubDir/myClass2.ts +export class MyClass2 {} +// @link: /home/src/workspaces/project/packages/mylib -> /home/src/workspaces/project/node_modules/mylib +// @Filename: /home/src/workspaces/project/src/index.ts + +const a = new MyClass/*1*/(); +const b = new MyClass2/*2*/();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.GoToMarker(t, "1") + f.SetFormatOption(t, "newLineCharacter", "\n") + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "MyClass", + Data: &lsproto.CompletionItemData{ + AutoImport: &lsproto.AutoImportData{ + ModuleSpecifier: "mylib", + }, + }, + AdditionalTextEdits: fourslash.AnyTextEdits, + SortText: PtrTo(string(ls.SortTextAutoImportSuggestions)), + }, + }, + }, + }) + f.VerifyApplyCodeActionFromCompletion(t, PtrTo("1"), &fourslash.ApplyCodeActionFromCompletionOptions{ + Name: "MyClass", + Source: "mylib", + Description: "Add import from \"mylib\"", + AutoImportData: &lsproto.AutoImportData{ + ExportName: "MyClass", + FileName: "/home/src/workspaces/project/packages/mylib/index.ts", + }, + NewFileContent: PtrTo(`import { MyClass } from "mylib"; + +const a = new MyClass(); +const b = new MyClass2();`), + }) +} diff --git a/internal/fourslash/tests/gen/chainedFatArrowFormatting_test.go b/internal/fourslash/tests/gen/chainedFatArrowFormatting_test.go new file mode 100644 index 0000000000..d9a6863d0f --- /dev/null +++ b/internal/fourslash/tests/gen/chainedFatArrowFormatting_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestChainedFatArrowFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var fn = () => () => null/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, `var fn = () => () => null;`) +} diff --git a/internal/fourslash/tests/gen/commentsBlocks_test.go b/internal/fourslash/tests/gen/commentsBlocks_test.go new file mode 100644 index 0000000000..c9d7d4cfef --- /dev/null +++ b/internal/fourslash/tests/gen/commentsBlocks_test.go @@ -0,0 +1,67 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCommentsBlocks(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/// 1 +var x, + /*2*/// 2 + y, +/*3*/ /* %3 */ + z; + +/*4*/ // 4 +switch (x) { +/*5*/ // 5 + case 1: +/*6*/ // 6 + break; +/*7*/ // 7 + case 2: +/*8*/ // 8 +} + +/*9*/ // 9 +if (true) +/*10*/ // 10 + ; +/*11*/ // 11 +else { +/*12*/ // 12 +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `// 1`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` // 2`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` /* %3 */`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `// 4`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` // 5`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` // 6`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` // 7`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, ` // 8`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, `// 9`) + f.GoToMarker(t, "10") + f.VerifyCurrentLineContent(t, ` // 10`) + f.GoToMarker(t, "11") + f.VerifyCurrentLineContent(t, `// 11`) + f.GoToMarker(t, "12") + f.VerifyCurrentLineContent(t, ` // 12`) +} diff --git a/internal/fourslash/tests/gen/completionsImport_addToNamedWithDifferentCacheValue_test.go b/internal/fourslash/tests/gen/completionsImport_addToNamedWithDifferentCacheValue_test.go new file mode 100644 index 0000000000..583d90b54e --- /dev/null +++ b/internal/fourslash/tests/gen/completionsImport_addToNamedWithDifferentCacheValue_test.go @@ -0,0 +1,96 @@ +package fourslash_test + +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/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsImport_addToNamedWithDifferentCacheValue(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/tsconfig.json +{ "compilerOptions": { "module": "commonjs" } } +// @Filename: /home/src/workspaces/project/packages/mylib/package.json +{ "name": "mylib", "version": "1.0.0", "main": "index.js" } +// @Filename: /home/src/workspaces/project/packages/mylib/index.ts +export * from "./mySubDir"; +// @Filename: /home/src/workspaces/project/packages/mylib/mySubDir/index.ts +export * from "./myClass"; +export * from "./myClass2"; +// @Filename: /home/src/workspaces/project/packages/mylib/mySubDir/myClass.ts +export class MyClass {} +// @Filename: /home/src/workspaces/project/packages/mylib/mySubDir/myClass2.ts +export class MyClass2 {} +// @link: /home/src/workspaces/project/packages/mylib -> /home/src/workspaces/project/node_modules/mylib +// @Filename: /home/src/workspaces/project/src/index.ts + +const a = new MyClass/*1*/(); +const b = new MyClass2/*2*/();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.GoToMarker(t, "1") + f.SetFormatOption(t, "newLineCharacter", "\n") + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "MyClass", + Data: &lsproto.CompletionItemData{ + AutoImport: &lsproto.AutoImportData{ + ModuleSpecifier: "../packages/mylib", + }, + }, + AdditionalTextEdits: fourslash.AnyTextEdits, + SortText: PtrTo(string(ls.SortTextAutoImportSuggestions)), + }, + }, + }, + }) + f.VerifyApplyCodeActionFromCompletion(t, PtrTo("1"), &fourslash.ApplyCodeActionFromCompletionOptions{ + Name: "MyClass", + Source: "../packages/mylib", + Description: "Add import from \"../packages/mylib\"", + AutoImportData: &lsproto.AutoImportData{ + ExportName: "MyClass", + FileName: "/home/src/workspaces/project/packages/mylib/index.ts", + }, + NewFileContent: PtrTo(`import { MyClass } from "../packages/mylib"; + +const a = new MyClass(); +const b = new MyClass2();`), + }) + f.ReplaceLine(t, 0, "import { MyClass } from \"mylib\";") + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "MyClass2", + Data: &lsproto.CompletionItemData{ + AutoImport: &lsproto.AutoImportData{ + ModuleSpecifier: "mylib", + }, + }, + AdditionalTextEdits: fourslash.AnyTextEdits, + SortText: PtrTo(string(ls.SortTextAutoImportSuggestions)), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsImport_jsModuleExportsAssignment_test.go b/internal/fourslash/tests/gen/completionsImport_jsModuleExportsAssignment_test.go new file mode 100644 index 0000000000..d87cc49c47 --- /dev/null +++ b/internal/fourslash/tests/gen/completionsImport_jsModuleExportsAssignment_test.go @@ -0,0 +1,88 @@ +package fourslash_test + +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/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsImport_jsModuleExportsAssignment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/tsconfig.json +{ "compilerOptions": { "module": "commonjs", "allowJs": true } } +// @Filename: /home/src/workspaces/project/third_party/marked/src/defaults.js +function getDefaults() { + return { + baseUrl: null, + }; +} + +function changeDefaults(newDefaults) { + module.exports.defaults = newDefaults; +} + +module.exports = { + defaults: getDefaults(), + getDefaults, + changeDefaults +}; +// @Filename: /home/src/workspaces/project/index.ts +/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.SetFormatOption(t, "newLineCharacter", "\n") + f.GoToMarker(t, "") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{}, + }) + f.Insert(t, "d") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "defaults", + Data: &lsproto.CompletionItemData{ + AutoImport: &lsproto.AutoImportData{ + ModuleSpecifier: "./third_party/marked/src/defaults", + }, + }, + AdditionalTextEdits: fourslash.AnyTextEdits, + SortText: PtrTo(string(ls.SortTextAutoImportSuggestions)), + }, + }, + Excludes: []string{ + "newDefaults", + }, + }, + }) + f.VerifyApplyCodeActionFromCompletion(t, PtrTo(""), &fourslash.ApplyCodeActionFromCompletionOptions{ + Name: "defaults", + Source: "./third_party/marked/src/defaults", + Description: "Add import from \"./third_party/marked/src/defaults\"", + AutoImportData: &lsproto.AutoImportData{ + ExportName: "defaults", + FileName: "/home/src/workspaces/project/third_party/marked/src/defaults.js", + ModuleSpecifier: "./third_party/marked/src/defaults", + }, + NewFileContent: PtrTo(`import { defaults } from "./third_party/marked/src/defaults"; + +d`), + }) +} diff --git a/internal/fourslash/tests/gen/consistenceOnIndentionsOfObjectsInAListAfterFormatting_test.go b/internal/fourslash/tests/gen/consistenceOnIndentionsOfObjectsInAListAfterFormatting_test.go new file mode 100644 index 0000000000..34df99fceb --- /dev/null +++ b/internal/fourslash/tests/gen/consistenceOnIndentionsOfObjectsInAListAfterFormatting_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestConsistenceOnIndentionsOfObjectsInAListAfterFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `foo({ +}, {/*1*/ +});/*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `}, {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `});`) +} diff --git a/internal/fourslash/tests/gen/constructorBraceFormatting_test.go b/internal/fourslash/tests/gen/constructorBraceFormatting_test.go new file mode 100644 index 0000000000..f67eba04b2 --- /dev/null +++ b/internal/fourslash/tests/gen/constructorBraceFormatting_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestConstructorBraceFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class X { + constructor () {}/*target*/ + /**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "}") + f.GoToMarker(t, "target") + f.VerifyCurrentLineContent(t, ` constructor() { }`) +} diff --git a/internal/fourslash/tests/gen/forceIndentAfterNewLineInsert_test.go b/internal/fourslash/tests/gen/forceIndentAfterNewLineInsert_test.go new file mode 100644 index 0000000000..2c4f16a083 --- /dev/null +++ b/internal/fourslash/tests/gen/forceIndentAfterNewLineInsert_test.go @@ -0,0 +1,36 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestForceIndentAfterNewLineInsert(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function f1() +{ return 0; } +function f2() +{ +return 0; +} +function g() +{ function h() { +return 0; +}}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `function f1() { return 0; } +function f2() { + return 0; +} +function g() { + function h() { + return 0; + } +}`) +} diff --git a/internal/fourslash/tests/gen/format01_test.go b/internal/fourslash/tests/gen/format01_test.go new file mode 100644 index 0000000000..bc4bd22c6e --- /dev/null +++ b/internal/fourslash/tests/gen/format01_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormat01(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/module Default{var x= ( { } ) ;}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.FormatDocument(t, "") + f.GoToMarker(t, "") + f.VerifyCurrentLineContent(t, `module Default { var x = ({}); }`) +} diff --git a/internal/fourslash/tests/gen/formatAfterMultilineComment_test.go b/internal/fourslash/tests/gen/formatAfterMultilineComment_test.go new file mode 100644 index 0000000000..40a12c87c3 --- /dev/null +++ b/internal/fourslash/tests/gen/formatAfterMultilineComment_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatAfterMultilineComment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*foo +*/"123123";` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `/*foo +*/"123123";`) +} diff --git a/internal/fourslash/tests/gen/formatAfterObjectLiteral_test.go b/internal/fourslash/tests/gen/formatAfterObjectLiteral_test.go new file mode 100644 index 0000000000..a34a88e249 --- /dev/null +++ b/internal/fourslash/tests/gen/formatAfterObjectLiteral_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatAfterObjectLiteral(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/module Default{var x= ( { } ) ;}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "") + f.VerifyCurrentLineContent(t, `module Default { var x = ({}); }`) +} diff --git a/internal/fourslash/tests/gen/formatAfterPasteInString_test.go b/internal/fourslash/tests/gen/formatAfterPasteInString_test.go new file mode 100644 index 0000000000..274e5a4a9f --- /dev/null +++ b/internal/fourslash/tests/gen/formatAfterPasteInString_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatAfterPasteInString(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*2*/const x = f('aa/*1*/a').x()` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Paste(t, "bb") + f.FormatDocument(t, "") + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `const x = f('aabba').x()`) +} diff --git a/internal/fourslash/tests/gen/formatAfterWhitespace_test.go b/internal/fourslash/tests/gen/formatAfterWhitespace_test.go new file mode 100644 index 0000000000..813d165b15 --- /dev/null +++ b/internal/fourslash/tests/gen/formatAfterWhitespace_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatAfterWhitespace(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function foo() +{ + var bar; + /*1*/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.InsertLine(t, "") + f.VerifyCurrentFileContent(t, `function foo() +{ + var bar; + + +}`) +} diff --git a/internal/fourslash/tests/gen/formatAnyTypeLiteral_test.go b/internal/fourslash/tests/gen/formatAnyTypeLiteral_test.go new file mode 100644 index 0000000000..100fc1b2c4 --- /dev/null +++ b/internal/fourslash/tests/gen/formatAnyTypeLiteral_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatAnyTypeLiteral(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function foo(x: { } /*objLit*/){ +/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "}") + f.GoToMarker(t, "objLit") + f.VerifyCurrentLineContent(t, `function foo(x: {}) {`) +} diff --git a/internal/fourslash/tests/gen/formatArrayLiteralExpression_test.go b/internal/fourslash/tests/gen/formatArrayLiteralExpression_test.go new file mode 100644 index 0000000000..66ed2fc0f8 --- /dev/null +++ b/internal/fourslash/tests/gen/formatArrayLiteralExpression_test.go @@ -0,0 +1,56 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatArrayLiteralExpression(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export let Things = [{ + Hat: 'hat', /*1*/ + Glove: 'glove', + Umbrella: 'umbrella' +},{/*2*/ + Salad: 'salad', /*3*/ + Burrito: 'burrito', + Pie: 'pie' + }];/*4*/ + +export let Things2 = [ +{ + Hat: 'hat', /*5*/ + Glove: 'glove', + Umbrella: 'umbrella' +}/*6*/, + { + Salad: 'salad', /*7*/ + Burrito: ['burrito', 'carne asada', 'tinga de res', 'tinga de pollo'], /*8*/ + Pie: 'pie' + }];/*9*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` Hat: 'hat',`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `}, {`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` Salad: 'salad',`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `}];`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` Hat: 'hat',`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` },`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` Salad: 'salad',`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, ` Burrito: ['burrito', 'carne asada', 'tinga de res', 'tinga de pollo'],`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, ` }];`) +} diff --git a/internal/fourslash/tests/gen/formatArrayOrObjectLiteralsInVariableList_test.go b/internal/fourslash/tests/gen/formatArrayOrObjectLiteralsInVariableList_test.go new file mode 100644 index 0000000000..03fe70126f --- /dev/null +++ b/internal/fourslash/tests/gen/formatArrayOrObjectLiteralsInVariableList_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatArrayOrObjectLiteralsInVariableList(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var v30 = [1, 2], v31, v32, v33 = [0], v34 = {'a': true}, v35;/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "") + f.VerifyCurrentLineContent(t, `var v30 = [1, 2], v31, v32, v33 = [0], v34 = { 'a': true }, v35;`) +} diff --git a/internal/fourslash/tests/gen/formatAsyncClassMethod1_test.go b/internal/fourslash/tests/gen/formatAsyncClassMethod1_test.go new file mode 100644 index 0000000000..1e0e8affda --- /dev/null +++ b/internal/fourslash/tests/gen/formatAsyncClassMethod1_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatAsyncClassMethod1(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + async foo() {} +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `class Foo { + async foo() { } +}`) +} diff --git a/internal/fourslash/tests/gen/formatAsyncClassMethod2_test.go b/internal/fourslash/tests/gen/formatAsyncClassMethod2_test.go new file mode 100644 index 0000000000..254c599e05 --- /dev/null +++ b/internal/fourslash/tests/gen/formatAsyncClassMethod2_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatAsyncClassMethod2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + private async foo() {} +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `class Foo { + private async foo() { } +}`) +} diff --git a/internal/fourslash/tests/gen/formatAsyncComputedMethod_test.go b/internal/fourslash/tests/gen/formatAsyncComputedMethod_test.go new file mode 100644 index 0000000000..35daef47e1 --- /dev/null +++ b/internal/fourslash/tests/gen/formatAsyncComputedMethod_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatAsyncComputedMethod(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + /*method*/async [0]() { } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "method") + f.VerifyCurrentLineContent(t, ` async [0]() { }`) +} diff --git a/internal/fourslash/tests/gen/formatAsyncKeyword_test.go b/internal/fourslash/tests/gen/formatAsyncKeyword_test.go new file mode 100644 index 0000000000..a90034aeb4 --- /dev/null +++ b/internal/fourslash/tests/gen/formatAsyncKeyword_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatAsyncKeyword(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/let x = async () => 1; +/*2*/let y = async() => 1; +/*3*/let z = async function () { return 1; };` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `let x = async () => 1;`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `let y = async () => 1;`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `let z = async function() { return 1; };`) +} diff --git a/internal/fourslash/tests/gen/formatBracketInSwitchCase_test.go b/internal/fourslash/tests/gen/formatBracketInSwitchCase_test.go new file mode 100644 index 0000000000..5e8964255f --- /dev/null +++ b/internal/fourslash/tests/gen/formatBracketInSwitchCase_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatBracketInSwitchCase(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `switch (x) { + case[]: +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `switch (x) { + case []: +}`) +} diff --git a/internal/fourslash/tests/gen/formatColonAndQMark_test.go b/internal/fourslash/tests/gen/formatColonAndQMark_test.go new file mode 100644 index 0000000000..5f861d540d --- /dev/null +++ b/internal/fourslash/tests/gen/formatColonAndQMark_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatColonAndQMark(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class foo {/*1*/ + constructor (n?: number, m = 5, o?: string) { }/*2*/ + x:number = 1?2:3;/*3*/ +}/*4*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `class foo {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` constructor(n?: number, m = 5, o?: string) { }`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` x: number = 1 ? 2 : 3;`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `}`) +} diff --git a/internal/fourslash/tests/gen/formatComments_test.go b/internal/fourslash/tests/gen/formatComments_test.go new file mode 100644 index 0000000000..0f8ae05317 --- /dev/null +++ b/internal/fourslash/tests/gen/formatComments_test.go @@ -0,0 +1,36 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatComments(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `_.chain() +// wow/*callChain1*/ + .then() +// waa/*callChain2*/ + .then(); +wow( + 3, +// uaa/*argument1*/ + 4 +// wua/*argument2*/ +);` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "callChain1") + f.VerifyCurrentLineContent(t, ` // wow`) + f.GoToMarker(t, "callChain2") + f.VerifyCurrentLineContent(t, ` // waa`) + f.GoToMarker(t, "argument1") + f.VerifyCurrentLineContent(t, ` // uaa`) + f.GoToMarker(t, "argument2") + f.VerifyCurrentLineContent(t, ` // wua`) +} diff --git a/internal/fourslash/tests/gen/formatConflictDiff3Marker1_test.go b/internal/fourslash/tests/gen/formatConflictDiff3Marker1_test.go new file mode 100644 index 0000000000..1015d9928c --- /dev/null +++ b/internal/fourslash/tests/gen/formatConflictDiff3Marker1_test.go @@ -0,0 +1,35 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatConflictDiff3Marker1(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { +<<<<<<< HEAD +v = 1; +||||||| merged common ancestors +v = 3; +======= +v = 2; +>>>>>>> Branch - a +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `class C { +<<<<<<< HEAD + v = 1; +||||||| merged common ancestors +v = 3; +======= +v = 2; +>>>>>>> Branch - a +}`) +} diff --git a/internal/fourslash/tests/gen/formatConflictMarker1_test.go b/internal/fourslash/tests/gen/formatConflictMarker1_test.go new file mode 100644 index 0000000000..76ef4931e8 --- /dev/null +++ b/internal/fourslash/tests/gen/formatConflictMarker1_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatConflictMarker1(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { +<<<<<<< HEAD +v = 1; +======= +v = 2; +>>>>>>> Branch - a +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `class C { +<<<<<<< HEAD + v = 1; +======= +v = 2; +>>>>>>> Branch - a +}`) +} diff --git a/internal/fourslash/tests/gen/formatControlFlowConstructs_test.go b/internal/fourslash/tests/gen/formatControlFlowConstructs_test.go new file mode 100644 index 0000000000..35499f198f --- /dev/null +++ b/internal/fourslash/tests/gen/formatControlFlowConstructs_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatControlFlowConstructs(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if (true)/**/ +{ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "") + f.VerifyCurrentLineContent(t, `if (true) {`) +} diff --git a/internal/fourslash/tests/gen/formatDebuggerStatement_test.go b/internal/fourslash/tests/gen/formatDebuggerStatement_test.go new file mode 100644 index 0000000000..3739025761 --- /dev/null +++ b/internal/fourslash/tests/gen/formatDebuggerStatement_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatDebuggerStatement(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if(false){debugger;} + if ( false ) { debugger ; }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToBOF(t) + f.VerifyCurrentLineContent(t, `if (false) { debugger; }`) + f.GoToEOF(t) + f.VerifyCurrentLineContent(t, `if (false) { debugger; }`) +} diff --git a/internal/fourslash/tests/gen/formatDocumentPreserveTrailingWhitespace_test.go b/internal/fourslash/tests/gen/formatDocumentPreserveTrailingWhitespace_test.go new file mode 100644 index 0000000000..a43e4cb786 --- /dev/null +++ b/internal/fourslash/tests/gen/formatDocumentPreserveTrailingWhitespace_test.go @@ -0,0 +1,38 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatDocumentPreserveTrailingWhitespace(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +var a; +var b + +// +function b(){ + while(true){ + } +} +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "trimTrailingWhitespace", false) + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, ` +var a; +var b + +// +function b() { + while (true) { + } +} +`) +} diff --git a/internal/fourslash/tests/gen/formatDocumentWithJSDoc_test.go b/internal/fourslash/tests/gen/formatDocumentWithJSDoc_test.go new file mode 100644 index 0000000000..6e45b393af --- /dev/null +++ b/internal/fourslash/tests/gen/formatDocumentWithJSDoc_test.go @@ -0,0 +1,41 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatDocumentWithJSDoc(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/** + * JSDoc for things + */ +function f() { + /** more + jsdoc */ + var t; + /** + * multiline + */ + var multiline; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `/** + * JSDoc for things + */ +function f() { + /** more + jsdoc */ + var t; + /** + * multiline + */ + var multiline; +}`) +} diff --git a/internal/fourslash/tests/gen/formatDocumentWithTrivia_test.go b/internal/fourslash/tests/gen/formatDocumentWithTrivia_test.go new file mode 100644 index 0000000000..933f71b799 --- /dev/null +++ b/internal/fourslash/tests/gen/formatDocumentWithTrivia_test.go @@ -0,0 +1,63 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatDocumentWithTrivia(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +// 1 below + +// 2 above + +let x; + +// abc + +let y; + +// 3 above + +while (true) { + while (true) { + } + + // 4 above +} + +// 5 above + + ` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, ` +// 1 below + +// 2 above + +let x; + +// abc + +let y; + +// 3 above + +while (true) { + while (true) { + } + + // 4 above +} + +// 5 above + +`) +} diff --git a/internal/fourslash/tests/gen/formatDotAfterNumber_test.go b/internal/fourslash/tests/gen/formatDotAfterNumber_test.go new file mode 100644 index 0000000000..03c96b43f3 --- /dev/null +++ b/internal/fourslash/tests/gen/formatDotAfterNumber_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatDotAfterNumber(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `1+ 2 .toString() +3/*1*/ +1+ 2. .toString() +3/*2*/ +1+ 2.0 .toString() +3/*3*/ +1+ (2) .toString() +3/*4*/ +1+ 2_000 .toString() +3/*5*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `1 + 2 .toString() + 3`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `1 + 2..toString() + 3`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `1 + 2.0.toString() + 3`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `1 + (2).toString() + 3`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `1 + 2_000 .toString() + 3`) +} diff --git a/internal/fourslash/tests/gen/formatEmptyBlock_test.go b/internal/fourslash/tests/gen/formatEmptyBlock_test.go new file mode 100644 index 0000000000..8eeaf90c1a --- /dev/null +++ b/internal/fourslash/tests/gen/formatEmptyBlock_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatEmptyBlock(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `{}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToEOF(t) + f.Insert(t, "\n") + f.GoToBOF(t) + f.VerifyCurrentLineContent(t, `{ }`) +} diff --git a/internal/fourslash/tests/gen/formatEmptyParamList_test.go b/internal/fourslash/tests/gen/formatEmptyParamList_test.go new file mode 100644 index 0000000000..bba10f7f1f --- /dev/null +++ b/internal/fourslash/tests/gen/formatEmptyParamList_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatEmptyParamList(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function f( f: function){/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "}") + f.VerifyCurrentLineContent(t, `function f(f: function) { }`) +} diff --git a/internal/fourslash/tests/gen/formatExportAssignment_test.go b/internal/fourslash/tests/gen/formatExportAssignment_test.go new file mode 100644 index 0000000000..54e8896c72 --- /dev/null +++ b/internal/fourslash/tests/gen/formatExportAssignment_test.go @@ -0,0 +1,19 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatExportAssignment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export='foo';` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `export = 'foo';`) +} diff --git a/internal/fourslash/tests/gen/formatIfTryCatchBlocks_test.go b/internal/fourslash/tests/gen/formatIfTryCatchBlocks_test.go new file mode 100644 index 0000000000..c442a34945 --- /dev/null +++ b/internal/fourslash/tests/gen/formatIfTryCatchBlocks_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatIfTryCatchBlocks(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `try { +} +catch { +} + +try { +} +catch (e) { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "PlaceOpenBraceOnNewLineForControlBlocks", true) + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `try +{ +} +catch +{ +} + +try +{ +} +catch (e) +{ +}`) +} diff --git a/internal/fourslash/tests/gen/formatIfWithEmptyCondition_test.go b/internal/fourslash/tests/gen/formatIfWithEmptyCondition_test.go new file mode 100644 index 0000000000..2c4bf360fa --- /dev/null +++ b/internal/fourslash/tests/gen/formatIfWithEmptyCondition_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatIfWithEmptyCondition(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if () { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "PlaceOpenBraceOnNewLineForControlBlocks", true) + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `if () +{ +}`) +} diff --git a/internal/fourslash/tests/gen/formatImplicitModule_test.go b/internal/fourslash/tests/gen/formatImplicitModule_test.go new file mode 100644 index 0000000000..49d2680d8c --- /dev/null +++ b/internal/fourslash/tests/gen/formatImplicitModule_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatImplicitModule(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` export class A { + + }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToBOF(t) + f.VerifyCurrentLineContent(t, `export class A {`) + f.GoToEOF(t) + f.VerifyCurrentLineContent(t, `}`) +} diff --git a/internal/fourslash/tests/gen/formatImportDeclaration_test.go b/internal/fourslash/tests/gen/formatImportDeclaration_test.go new file mode 100644 index 0000000000..0649847e5b --- /dev/null +++ b/internal/fourslash/tests/gen/formatImportDeclaration_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatImportDeclaration(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module Foo {/*1*/ +}/*2*/ + +import bar = Foo;/*3*/ + +import bar2=Foo;/*4*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `module Foo {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `import bar = Foo;`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `import bar2 = Foo;`) +} diff --git a/internal/fourslash/tests/gen/formatInTryCatchFinally_test.go b/internal/fourslash/tests/gen/formatInTryCatchFinally_test.go new file mode 100644 index 0000000000..c526c6c9ab --- /dev/null +++ b/internal/fourslash/tests/gen/formatInTryCatchFinally_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatInTryCatchFinally(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `try +{ + var x = 1/*1*/ +} +catch (e) +{ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, ` var x = 1;`) +} diff --git a/internal/fourslash/tests/gen/formatInTsxFiles_test.go b/internal/fourslash/tests/gen/formatInTsxFiles_test.go new file mode 100644 index 0000000000..dc28bc5898 --- /dev/null +++ b/internal/fourslash/tests/gen/formatInTsxFiles_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatInTsxFiles(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `//@Filename: file.tsx +interface I { + next: I` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `
`) +} diff --git a/internal/fourslash/tests/gen/formatLiteralTypeInUnionOrIntersectionType_test.go b/internal/fourslash/tests/gen/formatLiteralTypeInUnionOrIntersectionType_test.go new file mode 100644 index 0000000000..3bc0447516 --- /dev/null +++ b/internal/fourslash/tests/gen/formatLiteralTypeInUnionOrIntersectionType_test.go @@ -0,0 +1,49 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatLiteralTypeInUnionOrIntersectionType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `type NumberAndString = { + a: number +} & { + b: string +}; + +type NumberOrString = { + a: number +} | { + b: string +}; + +type Complexed = + Foo & + Bar | + Baz;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `type NumberAndString = { + a: number +} & { + b: string +}; + +type NumberOrString = { + a: number +} | { + b: string +}; + +type Complexed = + Foo & + Bar | + Baz;`) +} diff --git a/internal/fourslash/tests/gen/formatMultilineComment_test.go b/internal/fourslash/tests/gen/formatMultilineComment_test.go new file mode 100644 index 0000000000..f817a1acd9 --- /dev/null +++ b/internal/fourslash/tests/gen/formatMultilineComment_test.go @@ -0,0 +1,58 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatMultilineComment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*//** 1 + */*2*/2 +/*3*/ 3*/ + +class Foo { +/*4*//**4 + */*5*/5 +/*6*/ *6 +/*7*/ 7*/ + bar() { +/*8*/ /**8 + */*9*/9 +/*10*/ *10 +/*11*/ *11 +/*12*/ 12*/ + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `/** 1`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` *2`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` 3*/`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` /**4`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` *5`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` *6`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` 7*/`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, ` /**8`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, `*9`) + f.GoToMarker(t, "10") + f.VerifyCurrentLineContent(t, ` *10`) + f.GoToMarker(t, "11") + f.VerifyCurrentLineContent(t, ` *11`) + f.GoToMarker(t, "12") + f.VerifyCurrentLineContent(t, ` 12*/`) +} diff --git a/internal/fourslash/tests/gen/formatMultilineTypesWithMapped_test.go b/internal/fourslash/tests/gen/formatMultilineTypesWithMapped_test.go new file mode 100644 index 0000000000..895d711ea1 --- /dev/null +++ b/internal/fourslash/tests/gen/formatMultilineTypesWithMapped_test.go @@ -0,0 +1,87 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatMultilineTypesWithMapped(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `type Z = 'z' +type A = { + a: 'a' +} | { + [index in Z]: string + } +type B = { + b: 'b' +} & { + [index in Z]: string + } + +const c = { + c: 'c' +} as const satisfies { + [index in Z]: string + } + +const d = { + d: 'd' +} as const satisfies { + [index: string]: string +} + +const e = { + e: 'e' +} satisfies { + [index in Z]: string + } + +const f = { + f: 'f' +} satisfies { + [index: string]: string +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `type Z = 'z' +type A = { + a: 'a' +} | { + [index in Z]: string +} +type B = { + b: 'b' +} & { + [index in Z]: string +} + +const c = { + c: 'c' +} as const satisfies { + [index in Z]: string +} + +const d = { + d: 'd' +} as const satisfies { + [index: string]: string +} + +const e = { + e: 'e' +} satisfies { + [index in Z]: string +} + +const f = { + f: 'f' +} satisfies { + [index: string]: string +}`) +} diff --git a/internal/fourslash/tests/gen/formatMultipleFunctionArguments_test.go b/internal/fourslash/tests/gen/formatMultipleFunctionArguments_test.go new file mode 100644 index 0000000000..f781b0c3b7 --- /dev/null +++ b/internal/fourslash/tests/gen/formatMultipleFunctionArguments_test.go @@ -0,0 +1,57 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatMultipleFunctionArguments(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` + someRandomFunction({ + prop1: 1, + prop2: 2 + }, { + prop3: 3, + prop4: 4 + }, { + prop5: 5, + prop6: 6 + }); + + someRandomFunction( + { prop7: 1, prop8: 2 }, + { prop9: 3, prop10: 4 }, + { + prop11: 5, + prop2: 6 + } + );` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, ` +someRandomFunction({ + prop1: 1, + prop2: 2 +}, { + prop3: 3, + prop4: 4 +}, { + prop5: 5, + prop6: 6 +}); + +someRandomFunction( + { prop7: 1, prop8: 2 }, + { prop9: 3, prop10: 4 }, + { + prop11: 5, + prop2: 6 + } +);`) +} diff --git a/internal/fourslash/tests/gen/formatNestedClassWithOpenBraceOnNewLines_test.go b/internal/fourslash/tests/gen/formatNestedClassWithOpenBraceOnNewLines_test.go new file mode 100644 index 0000000000..2a67ad12dc --- /dev/null +++ b/internal/fourslash/tests/gen/formatNestedClassWithOpenBraceOnNewLines_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatNestedClassWithOpenBraceOnNewLines(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module A +{ + class B { + /*1*/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "PlaceOpenBraceOnNewLineForControlBlocks", true) + f.SetFormatOption(t, "PlaceOpenBraceOnNewLineForFunctions", true) + f.GoToMarker(t, "1") + f.Insert(t, "}") + f.VerifyCurrentFileContent(t, `module A +{ + class B + { + } +}`) +} diff --git a/internal/fourslash/tests/gen/formatNoSpaceAfterTemplateHeadAndMiddle_test.go b/internal/fourslash/tests/gen/formatNoSpaceAfterTemplateHeadAndMiddle_test.go new file mode 100644 index 0000000000..780f9bc6a7 --- /dev/null +++ b/internal/fourslash/tests/gen/formatNoSpaceAfterTemplateHeadAndMiddle_test.go @@ -0,0 +1,49 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatNoSpaceAfterTemplateHeadAndMiddle(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `const a1 = ` + "`" + `${ 1 }${ 1 }` + "`" + `; +const a2 = ` + "`" + ` + ${ 1 }${ 1 } +` + "`" + `; +const a3 = ` + "`" + ` + + + ${ 1 }${ 1 } +` + "`" + `; +const a4 = ` + "`" + ` + + ${ 1 }${ 1 } + +` + "`" + `; +const a5 = ` + "`" + `text ${ 1 } text ${ 1 } text` + "`" + `; +const a6 = ` + "`" + ` + text ${ 1 } + text ${ 1 } + text +` + "`" + `;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces", false) + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, "const a1 = `${1}${1}`;\n"+"const a2 = `\n"+` ${1}${1} +`+"`;\n"+"const a3 = `\n"+` +`+` +`+` ${1}${1} +`+"`;\n"+"const a4 = `\n"+` +`+` ${1}${1} +`+` +`+"`;\n"+"const a5 = `text ${1} text ${1} text`;\n"+"const a6 = `\n"+` text ${1} +`+` text ${1} +`+` text +`+"`;") +} diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace1_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace1_test.go new file mode 100644 index 0000000000..7b85553d7a --- /dev/null +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace1_test.go @@ -0,0 +1,19 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatNoSpaceBeforeCloseBrace1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `new Foo(1, /* comment */ );` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `new Foo(1, /* comment */);`) +} diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace2_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace2_test.go new file mode 100644 index 0000000000..1c8735b8a5 --- /dev/null +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace2_test.go @@ -0,0 +1,19 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatNoSpaceBeforeCloseBrace2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `new Foo(1, );` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `new Foo(1,);`) +} diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace3_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace3_test.go new file mode 100644 index 0000000000..a10e4fbbbb --- /dev/null +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace3_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatNoSpaceBeforeCloseBrace3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `foo( + 1, /* comment */ );` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `foo( + 1, /* comment */);`) +} diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace4_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace4_test.go new file mode 100644 index 0000000000..139af8917d --- /dev/null +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace4_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatNoSpaceBeforeCloseBrace4(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `new Foo(1 +, /* comment */ );` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `new Foo(1 + , /* comment */);`) +} diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace5_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace5_test.go new file mode 100644 index 0000000000..3b85a3ab16 --- /dev/null +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace5_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatNoSpaceBeforeCloseBrace5(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `new Foo(1, + /* comment */ );` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `new Foo(1, + /* comment */);`) +} diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace6_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace6_test.go new file mode 100644 index 0000000000..9c31fb4e62 --- /dev/null +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace6_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatNoSpaceBeforeCloseBrace6(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `new Foo(1, /* comment */ + );` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `new Foo(1, /* comment */ +);`) +} diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace_test.go new file mode 100644 index 0000000000..b93fb4be25 --- /dev/null +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace_test.go @@ -0,0 +1,19 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatNoSpaceBeforeCloseBrace(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `foo(1, /* comment */ );` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `foo(1, /* comment */);`) +} diff --git a/internal/fourslash/tests/gen/formatNoSpaceBetweenClosingParenAndTemplateString_test.go b/internal/fourslash/tests/gen/formatNoSpaceBetweenClosingParenAndTemplateString_test.go new file mode 100644 index 0000000000..af248c75e1 --- /dev/null +++ b/internal/fourslash/tests/gen/formatNoSpaceBetweenClosingParenAndTemplateString_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatNoSpaceBetweenClosingParenAndTemplateString(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `foo() ` + "`" + `abc` + "`" + `; +bar()` + "`" + `def` + "`" + `; +baz()` + "`" + `a${x}b` + "`" + `;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, "foo()`abc`;\nbar()`def`;\nbaz()`a${x}b`;") +} diff --git a/internal/fourslash/tests/gen/formatObjectBindingPattern_restElementWithPropertyName_test.go b/internal/fourslash/tests/gen/formatObjectBindingPattern_restElementWithPropertyName_test.go new file mode 100644 index 0000000000..78bfa16efe --- /dev/null +++ b/internal/fourslash/tests/gen/formatObjectBindingPattern_restElementWithPropertyName_test.go @@ -0,0 +1,19 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatObjectBindingPattern_restElementWithPropertyName(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `const { ...a: b } = {};` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `const { ...a: b } = {};`) +} diff --git a/internal/fourslash/tests/gen/formatObjectBindingPattern_test.go b/internal/fourslash/tests/gen/formatObjectBindingPattern_test.go new file mode 100644 index 0000000000..9b19da613b --- /dev/null +++ b/internal/fourslash/tests/gen/formatObjectBindingPattern_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatObjectBindingPattern(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `const { +x, +y, +} = 0;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `const { + x, + y, +} = 0;`) +} diff --git a/internal/fourslash/tests/gen/formatOnEnterFunctionDeclaration_test.go b/internal/fourslash/tests/gen/formatOnEnterFunctionDeclaration_test.go new file mode 100644 index 0000000000..f34f78439f --- /dev/null +++ b/internal/fourslash/tests/gen/formatOnEnterFunctionDeclaration_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatOnEnterFunctionDeclaration(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*0*/function listAPIFiles(path: string): string[] {/*1*/ }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.InsertLine(t, "") + f.GoToMarker(t, "0") + f.VerifyCurrentLineContent(t, `function listAPIFiles(path: string): string[] {`) +} diff --git a/internal/fourslash/tests/gen/formatOnEnterInComment_test.go b/internal/fourslash/tests/gen/formatOnEnterInComment_test.go new file mode 100644 index 0000000000..5ad048fa99 --- /dev/null +++ b/internal/fourslash/tests/gen/formatOnEnterInComment_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatOnEnterInComment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` /** + * /*1*/ + */` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.InsertLine(t, "") + f.VerifyCurrentFileContent(t, ` /** + * + + */`) +} diff --git a/internal/fourslash/tests/gen/formatOnEnterOpenBraceAddNewLine_test.go b/internal/fourslash/tests/gen/formatOnEnterOpenBraceAddNewLine_test.go new file mode 100644 index 0000000000..2741fbb9f5 --- /dev/null +++ b/internal/fourslash/tests/gen/formatOnEnterOpenBraceAddNewLine_test.go @@ -0,0 +1,35 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatOnEnterOpenBraceAddNewLine(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if(true) {/*0*/} +if(false)/*1*/{ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "PlaceOpenBraceOnNewLineForControlBlocks", true) + f.GoToMarker(t, "0") + f.InsertLine(t, "") + f.VerifyCurrentFileContent(t, `if (true) +{ +} +if(false){ +}`) + f.GoToMarker(t, "1") + f.InsertLine(t, "") + f.VerifyCurrentFileContent(t, `if (true) +{ +} +if (false) +{ +}`) +} diff --git a/internal/fourslash/tests/gen/formatOnOpenCurlyBraceRemoveNewLine_test.go b/internal/fourslash/tests/gen/formatOnOpenCurlyBraceRemoveNewLine_test.go new file mode 100644 index 0000000000..9c3127855e --- /dev/null +++ b/internal/fourslash/tests/gen/formatOnOpenCurlyBraceRemoveNewLine_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatOnOpenCurlyBraceRemoveNewLine(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if(true) +/**/ }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "PlaceOpenBraceOnNewLineForControlBlocks", false) + f.GoToMarker(t, "") + f.Insert(t, "{") + f.VerifyCurrentFileContent(t, `if (true) { }`) +} diff --git a/internal/fourslash/tests/gen/formatOnSemiColonAfterBreak_test.go b/internal/fourslash/tests/gen/formatOnSemiColonAfterBreak_test.go new file mode 100644 index 0000000000..87d7df0738 --- /dev/null +++ b/internal/fourslash/tests/gen/formatOnSemiColonAfterBreak_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatOnSemiColonAfterBreak(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `for (var a in b) { +break/**/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, ` break;`) +} diff --git a/internal/fourslash/tests/gen/formatParameter_test.go b/internal/fourslash/tests/gen/formatParameter_test.go new file mode 100644 index 0000000000..8abf36ee99 --- /dev/null +++ b/internal/fourslash/tests/gen/formatParameter_test.go @@ -0,0 +1,35 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatParameter(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function foo( + first: + number,/*first*/ + second: ( + string/*second*/ + ), + third: + ( + boolean/*third*/ + ) +) { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "first") + f.VerifyCurrentLineContent(t, ` number,`) + f.GoToMarker(t, "second") + f.VerifyCurrentLineContent(t, ` string`) + f.GoToMarker(t, "third") + f.VerifyCurrentLineContent(t, ` boolean`) +} diff --git a/internal/fourslash/tests/gen/formatRemoveNewLineAfterOpenBrace_test.go b/internal/fourslash/tests/gen/formatRemoveNewLineAfterOpenBrace_test.go new file mode 100644 index 0000000000..68da02fd12 --- /dev/null +++ b/internal/fourslash/tests/gen/formatRemoveNewLineAfterOpenBrace_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatRemoveNewLineAfterOpenBrace(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function foo() +{ +} +if (true) +{ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `function foo() { +} +if (true) { +}`) +} diff --git a/internal/fourslash/tests/gen/formatRemoveSpaceBetweenDotDotDotAndTypeName_test.go b/internal/fourslash/tests/gen/formatRemoveSpaceBetweenDotDotDotAndTypeName_test.go new file mode 100644 index 0000000000..9bb6b7c7e0 --- /dev/null +++ b/internal/fourslash/tests/gen/formatRemoveSpaceBetweenDotDotDotAndTypeName_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatRemoveSpaceBetweenDotDotDotAndTypeName(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let a: [... any[]]; +let b: [... number[]]; +let c: [... string[]];` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `let a: [...any[]]; +let b: [...number[]]; +let c: [...string[]];`) +} diff --git a/internal/fourslash/tests/gen/formatSatisfiesExpression_test.go b/internal/fourslash/tests/gen/formatSatisfiesExpression_test.go new file mode 100644 index 0000000000..5d61e1fd0b --- /dev/null +++ b/internal/fourslash/tests/gen/formatSatisfiesExpression_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatSatisfiesExpression(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `type Foo = "a" | "b" | "c"; +const foo1 = ["a"] satisfies Foo[]; +const foo2 = ["a"]satisfies Foo[]; +const foo3 = ["a"] satisfies Foo[];` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `type Foo = "a" | "b" | "c"; +const foo1 = ["a"] satisfies Foo[]; +const foo2 = ["a"] satisfies Foo[]; +const foo3 = ["a"] satisfies Foo[];`) +} diff --git a/internal/fourslash/tests/gen/formatSpaceAfterImplementsExtends_test.go b/internal/fourslash/tests/gen/formatSpaceAfterImplementsExtends_test.go new file mode 100644 index 0000000000..f866052d4b --- /dev/null +++ b/internal/fourslash/tests/gen/formatSpaceAfterImplementsExtends_test.go @@ -0,0 +1,39 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatSpaceAfterImplementsExtends(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C1 implements Array{ +} + +class C2 implements Number{ +} + +class C3 extends Array{ +} + +class C4 extends Number{ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `class C1 implements Array { +} + +class C2 implements Number { +} + +class C3 extends Array { +} + +class C4 extends Number { +}`) +} diff --git a/internal/fourslash/tests/gen/formatSpaceAfterTemplateHeadAndMiddle_test.go b/internal/fourslash/tests/gen/formatSpaceAfterTemplateHeadAndMiddle_test.go new file mode 100644 index 0000000000..0bc31df184 --- /dev/null +++ b/internal/fourslash/tests/gen/formatSpaceAfterTemplateHeadAndMiddle_test.go @@ -0,0 +1,49 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatSpaceAfterTemplateHeadAndMiddle(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `const a1 = ` + "`" + `${1}${1}` + "`" + `; +const a2 = ` + "`" + ` + ${1}${1} +` + "`" + `; +const a3 = ` + "`" + ` + + + ${1}${1} +` + "`" + `; +const a4 = ` + "`" + ` + + ${1}${1} + +` + "`" + `; +const a5 = ` + "`" + `text ${1} text ${1} text` + "`" + `; +const a6 = ` + "`" + ` + text ${1} + text ${1} + text +` + "`" + `;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces", true) + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, "const a1 = `${ 1 }${ 1 }`;\n"+"const a2 = `\n"+` ${ 1 }${ 1 } +`+"`;\n"+"const a3 = `\n"+` +`+` +`+` ${ 1 }${ 1 } +`+"`;\n"+"const a4 = `\n"+` +`+` ${ 1 }${ 1 } +`+` +`+"`;\n"+"const a5 = `text ${ 1 } text ${ 1 } text`;\n"+"const a6 = `\n"+` text ${ 1 } +`+` text ${ 1 } +`+` text +`+"`;") +} diff --git a/internal/fourslash/tests/gen/formatSpaceBetweenFunctionAndArrayIndex_test.go b/internal/fourslash/tests/gen/formatSpaceBetweenFunctionAndArrayIndex_test.go new file mode 100644 index 0000000000..efc680cce8 --- /dev/null +++ b/internal/fourslash/tests/gen/formatSpaceBetweenFunctionAndArrayIndex_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatSpaceBetweenFunctionAndArrayIndex(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +function test() { + return []; +} + +test() [0] +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, ` +function test() { + return []; +} + +test()[0] +`) +} diff --git a/internal/fourslash/tests/gen/formatTSXWithInlineComment_test.go b/internal/fourslash/tests/gen/formatTSXWithInlineComment_test.go new file mode 100644 index 0000000000..614022116c --- /dev/null +++ b/internal/fourslash/tests/gen/formatTSXWithInlineComment_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatTSXWithInlineComment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: foo.tsx +const a =
+ // +
` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `const a = `) +} diff --git a/internal/fourslash/tests/gen/formatTryCatch_test.go b/internal/fourslash/tests/gen/formatTryCatch_test.go new file mode 100644 index 0000000000..0025776f04 --- /dev/null +++ b/internal/fourslash/tests/gen/formatTryCatch_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatTryCatch(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function test() { + /*try*/try { + } + /*catch*/catch (e) { + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.FormatDocument(t, "") + f.FormatDocument(t, "") + f.GoToMarker(t, "try") + f.VerifyCurrentLineContent(t, ` try {`) + f.GoToMarker(t, "catch") + f.VerifyCurrentLineContent(t, ` catch (e) {`) +} diff --git a/internal/fourslash/tests/gen/formatTryFinally_test.go b/internal/fourslash/tests/gen/formatTryFinally_test.go new file mode 100644 index 0000000000..e5c531a041 --- /dev/null +++ b/internal/fourslash/tests/gen/formatTryFinally_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatTryFinally(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if (true) try { + // ... +} finally { + // ... +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `if (true) try { + // ... +} finally { + // ... +}`) +} diff --git a/internal/fourslash/tests/gen/formatTsxClosingAfterJsxText_test.go b/internal/fourslash/tests/gen/formatTsxClosingAfterJsxText_test.go new file mode 100644 index 0000000000..f6908c72bc --- /dev/null +++ b/internal/fourslash/tests/gen/formatTsxClosingAfterJsxText_test.go @@ -0,0 +1,44 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatTsxClosingAfterJsxText(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: foo.tsx + +const a = ( +
+ text +
+) +const b = ( +
+ text + twice +
+) +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, ` +const a = ( +
+ text +
+) +const b = ( +
+ text + twice +
+) +`) +} diff --git a/internal/fourslash/tests/gen/formatTsxMultilineAttributeString_test.go b/internal/fourslash/tests/gen/formatTsxMultilineAttributeString_test.go new file mode 100644 index 0000000000..8d2a939713 --- /dev/null +++ b/internal/fourslash/tests/gen/formatTsxMultilineAttributeString_test.go @@ -0,0 +1,30 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatTsxMultilineAttributeString(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: foo.tsx +( + +);` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `( + +);`) +} diff --git a/internal/fourslash/tests/gen/formatTsx_test.go b/internal/fourslash/tests/gen/formatTsx_test.go new file mode 100644 index 0000000000..9de78e0383 --- /dev/null +++ b/internal/fourslash/tests/gen/formatTsx_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatTsx(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: foo.tsx +

'

{function(){return 1;}]}

` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `

'

{function() { return 1; }]}

`) +} diff --git a/internal/fourslash/tests/gen/formatTypeAnnotation1_test.go b/internal/fourslash/tests/gen/formatTypeAnnotation1_test.go new file mode 100644 index 0000000000..6c501cc988 --- /dev/null +++ b/internal/fourslash/tests/gen/formatTypeAnnotation1_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatTypeAnnotation1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function foo(x: number, y?: string): number {} +interface Foo { + x: number; + y?: number; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "insertSpaceBeforeTypeAnnotation", true) + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `function foo(x : number, y ?: string) : number { } +interface Foo { + x : number; + y ?: number; +}`) +} diff --git a/internal/fourslash/tests/gen/formatTypeAnnotation2_test.go b/internal/fourslash/tests/gen/formatTypeAnnotation2_test.go new file mode 100644 index 0000000000..62cb057f97 --- /dev/null +++ b/internal/fourslash/tests/gen/formatTypeAnnotation2_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatTypeAnnotation2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function foo(x : number, y ?: string) : number {} +interface Foo { + x : number; + y ?: number; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `function foo(x: number, y?: string): number { } +interface Foo { + x: number; + y?: number; +}`) +} diff --git a/internal/fourslash/tests/gen/formatTypeArgumentOnNewLine_test.go b/internal/fourslash/tests/gen/formatTypeArgumentOnNewLine_test.go new file mode 100644 index 0000000000..0a400531d4 --- /dev/null +++ b/internal/fourslash/tests/gen/formatTypeArgumentOnNewLine_test.go @@ -0,0 +1,30 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatTypeArgumentOnNewLine(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `const genericObject = new GenericObject< + /*1*/{} +>(); +const genericObject2 = new GenericObject2< + /*2*/{}, + /*3*/{} +>();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` {}`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` {},`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` {}`) +} diff --git a/internal/fourslash/tests/gen/formatTypeParameters_test.go b/internal/fourslash/tests/gen/formatTypeParameters_test.go new file mode 100644 index 0000000000..23fe8fb8b4 --- /dev/null +++ b/internal/fourslash/tests/gen/formatTypeParameters_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatTypeParameters(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/type Bar = T` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "") + f.VerifyCurrentLineContent(t, `type Bar = T`) +} diff --git a/internal/fourslash/tests/gen/formatVariableDeclarationList_test.go b/internal/fourslash/tests/gen/formatVariableDeclarationList_test.go new file mode 100644 index 0000000000..6484728cef --- /dev/null +++ b/internal/fourslash/tests/gen/formatVariableDeclarationList_test.go @@ -0,0 +1,54 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatVariableDeclarationList(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/var fun1 = function ( ) { +/*2*/ var x = 'foo' , +/*3*/ z = 'bar' ; +/*4*/ return x ; +/*5*/}, + +/*6*/fun2 = ( function ( f ) { +/*7*/ var fun = function ( ) { +/*8*/ console . log ( f ( ) ) ; +/*9*/ }, +/*10*/ x = 'Foo' ; +/*11*/ return fun ; +/*12*/} ( fun1 ) ) ;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `var fun1 = function() {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` var x = 'foo',`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` z = 'bar';`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` return x;`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `},`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` fun2 = (function(f) {`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` var fun = function() {`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, ` console.log(f());`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, ` },`) + f.GoToMarker(t, "10") + f.VerifyCurrentLineContent(t, ` x = 'Foo';`) + f.GoToMarker(t, "11") + f.VerifyCurrentLineContent(t, ` return fun;`) + f.GoToMarker(t, "12") + f.VerifyCurrentLineContent(t, ` }(fun1));`) +} diff --git a/internal/fourslash/tests/gen/formatWithStatement_test.go b/internal/fourslash/tests/gen/formatWithStatement_test.go new file mode 100644 index 0000000000..7ef56b55bc --- /dev/null +++ b/internal/fourslash/tests/gen/formatWithStatement_test.go @@ -0,0 +1,45 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatWithStatement(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `with /*1*/(foo.bar) + + {/*2*/ + + }/*3*/ + +with (bar.blah)/*4*/ +{/*5*/ +}/*6*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "PlaceOpenBraceOnNewLineForControlBlocks", false) + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `with (foo.bar) {`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `with (bar.blah) {`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, `}`) + f.SetFormatOption(t, "PlaceOpenBraceOnNewLineForControlBlocks", true) + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `with (foo.bar)`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `{`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `with (bar.blah)`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `{`) +} diff --git a/internal/fourslash/tests/gen/formatonkey01_test.go b/internal/fourslash/tests/gen/formatonkey01_test.go new file mode 100644 index 0000000000..61e6c378a3 --- /dev/null +++ b/internal/fourslash/tests/gen/formatonkey01_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatonkey01(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `switch (1) { + case 1: + { + /*1*/ + break; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.GoToMarker(t, "1") + f.Insert(t, "}") + f.VerifyCurrentLineContent(t, ` }`) +} diff --git a/internal/fourslash/tests/gen/formattingAfterChainedFatArrow_test.go b/internal/fourslash/tests/gen/formattingAfterChainedFatArrow_test.go new file mode 100644 index 0000000000..4b67c9e840 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingAfterChainedFatArrow_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingAfterChainedFatArrow(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = n => p => { + while (true) { + void 0; + }/**/ +};` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.FormatDocument(t, "") + f.VerifyCurrentLineContent(t, ` }`) +} diff --git a/internal/fourslash/tests/gen/formattingAfterMultiLineIfCondition_test.go b/internal/fourslash/tests/gen/formattingAfterMultiLineIfCondition_test.go new file mode 100644 index 0000000000..9ee17ae690 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingAfterMultiLineIfCondition_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingAfterMultiLineIfCondition(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` var foo; + if (foo && + foo) { +/*comment*/ // This is a comment + foo.toString(); + /**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "}") + f.GoToMarker(t, "comment") + f.VerifyCurrentLineContent(t, ` // This is a comment`) +} diff --git a/internal/fourslash/tests/gen/formattingAfterMultiLineString_test.go b/internal/fourslash/tests/gen/formattingAfterMultiLineString_test.go new file mode 100644 index 0000000000..ba63950557 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingAfterMultiLineString_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingAfterMultiLineString(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class foo { + stop() { + var s = "hello\/*1*/ +"/*2*/ + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "2") + f.InsertLine(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, " var s = \"hello\\") +} diff --git a/internal/fourslash/tests/gen/formattingArrayLiteral_test.go b/internal/fourslash/tests/gen/formattingArrayLiteral_test.go new file mode 100644 index 0000000000..56c018a157 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingArrayLiteral_test.go @@ -0,0 +1,41 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingArrayLiteral(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/x= []; +y = [ +/*2*/ 1, +/*3*/ 2 +/*4*/ ]; + +z = [[ +/*5*/ 1, +/*6*/ 2 +/*7*/ ] ];` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `x = [];`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` 1,`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` 2`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `];`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` 1,`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` 2`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, `]];`) +} diff --git a/internal/fourslash/tests/gen/formattingAwait_test.go b/internal/fourslash/tests/gen/formattingAwait_test.go new file mode 100644 index 0000000000..b1ed32e643 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingAwait_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingAwait(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `async function f() { + for await (const x of g()) { + console.log(x); + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `async function f() { + for await (const x of g()) { + console.log(x); + } +}`) +} diff --git a/internal/fourslash/tests/gen/formattingBlockInCaseClauses_test.go b/internal/fourslash/tests/gen/formattingBlockInCaseClauses_test.go new file mode 100644 index 0000000000..9006375266 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingBlockInCaseClauses_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingBlockInCaseClauses(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `switch (1) { + case 1: + { + /*1*/ + break; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "}") + f.VerifyCurrentLineContent(t, ` }`) +} diff --git a/internal/fourslash/tests/gen/formattingChainingMethods_test.go b/internal/fourslash/tests/gen/formattingChainingMethods_test.go new file mode 100644 index 0000000000..387acb7a19 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingChainingMethods_test.go @@ -0,0 +1,57 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingChainingMethods(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` z$ = this.store.select(this.fake()) + .ofType( + 'ACTION', + 'ACTION-2' + ) + .pipe( + filter(x => !!x), + switchMap(() => + this.store.select(this.menuSelector.getAll('x')) + .pipe( + tap(x => { + this.x = !x; + }) + ) + ) + ); + +1 + .toFixed( + 2);` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `z$ = this.store.select(this.fake()) + .ofType( + 'ACTION', + 'ACTION-2' + ) + .pipe( + filter(x => !!x), + switchMap(() => + this.store.select(this.menuSelector.getAll('x')) + .pipe( + tap(x => { + this.x = !x; + }) + ) + ) + ); + +1 + .toFixed( + 2);`) +} diff --git a/internal/fourslash/tests/gen/formattingComma_test.go b/internal/fourslash/tests/gen/formattingComma_test.go new file mode 100644 index 0000000000..e65f55a890 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingComma_test.go @@ -0,0 +1,50 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingComma(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = [1 , 2];/*x*/ +var y = ( 1 , 2 );/*y*/ +var z1 = 1 , zz = 2;/*z1*/ +var z2 = { + x: 1 ,/*z2*/ + y: 2 +}; +var z3 = ( + () => { } ,/*z3*/ + () => { } + ); +var z4 = [ + () => { } ,/*z4*/ + () => { } +]; +var z5 = { + x: () => { } ,/*z5*/ + y: () => { } +}; ` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "x") + f.VerifyCurrentLineContent(t, `var x = [1, 2];`) + f.GoToMarker(t, "y") + f.VerifyCurrentLineContent(t, `var y = (1, 2);`) + f.GoToMarker(t, "z1") + f.VerifyCurrentLineContent(t, `var z1 = 1, zz = 2;`) + f.GoToMarker(t, "z2") + f.VerifyCurrentLineContent(t, ` x: 1,`) + f.GoToMarker(t, "z3") + f.VerifyCurrentLineContent(t, ` () => { },`) + f.GoToMarker(t, "z4") + f.VerifyCurrentLineContent(t, ` () => { },`) + f.GoToMarker(t, "z5") + f.VerifyCurrentLineContent(t, ` x: () => { },`) +} diff --git a/internal/fourslash/tests/gen/formattingCommentsBeforeErrors_test.go b/internal/fourslash/tests/gen/formattingCommentsBeforeErrors_test.go new file mode 100644 index 0000000000..85e90f3fb3 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingCommentsBeforeErrors_test.go @@ -0,0 +1,33 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingCommentsBeforeErrors(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module A { + interface B { + // a + // b + baz(); +/*0*/ // d /*1*/asd a + // e + foo(); + // f asd + // g as + bar(); + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "\n") + f.GoToMarker(t, "0") + f.VerifyCurrentLineContent(t, ` // d `) +} diff --git a/internal/fourslash/tests/gen/formattingConditionalOperator_test.go b/internal/fourslash/tests/gen/formattingConditionalOperator_test.go new file mode 100644 index 0000000000..2cf1809bb5 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingConditionalOperator_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingConditionalOperator(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x=true?1:2` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToBOF(t) + f.VerifyCurrentLineContent(t, `var x = true ? 1 : 2`) +} diff --git a/internal/fourslash/tests/gen/formattingConditionalTypes_test.go b/internal/fourslash/tests/gen/formattingConditionalTypes_test.go new file mode 100644 index 0000000000..165aefd54c --- /dev/null +++ b/internal/fourslash/tests/gen/formattingConditionalTypes_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingConditionalTypes(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*L1*/type Diff1 = T extends U?never:T; +/*L2*/type Diff2 = T extends U ? never : T;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "L1") + f.VerifyCurrentLineContent(t, `type Diff1 = T extends U ? never : T;`) + f.GoToMarker(t, "L2") + f.VerifyCurrentLineContent(t, `type Diff2 = T extends U ? never : T;`) +} diff --git a/internal/fourslash/tests/gen/formattingCrash_test.go b/internal/fourslash/tests/gen/formattingCrash_test.go new file mode 100644 index 0000000000..a0ae593602 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingCrash_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingCrash(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/module Default{ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "PlaceOpenBraceOnNewLineForFunctions", true) + f.SetFormatOption(t, "PlaceOpenBraceOnNewLineForControlBlocks", true) + f.FormatDocument(t, "") + f.GoToMarker(t, "") + f.VerifyCurrentLineContent(t, `module Default`) +} diff --git a/internal/fourslash/tests/gen/formattingDecorators_test.go b/internal/fourslash/tests/gen/formattingDecorators_test.go new file mode 100644 index 0000000000..5385c3e236 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingDecorators_test.go @@ -0,0 +1,125 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingDecorators(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/ @ decorator1 +/*2*/ @ decorator2 +/*3*/ @decorator3 +/*4*/ @ decorator4 @ decorator5 +/*5*/class C { +/*6*/ @ decorator6 +/*7*/ @ decorator7 +/*8*/ @decorator8 +/*9*/ method1() { } + +/*10*/ @ decorator9 @ decorator10 @decorator11 method2() { } + + method3( +/*11*/ @ decorator12 +/*12*/ @ decorator13 +/*13*/ @decorator14 +/*14*/ x) { } + + method4( +/*15*/ @ decorator15 @ decorator16 @decorator17 x) { } + +/*16*/ @ decorator18 +/*17*/ @ decorator19 +/*18*/ @decorator20 +/*19*/ ["computed1"]() { } + +/*20*/ @ decorator21 @ decorator22 @decorator23 ["computed2"]() { } + +/*21*/ @ decorator24 +/*22*/ @ decorator25 +/*23*/ @decorator26 +/*24*/ get accessor1() { } + +/*25*/ @ decorator27 @ decorator28 @decorator29 get accessor2() { } + +/*26*/ @ decorator30 +/*27*/ @ decorator31 +/*28*/ @decorator32 +/*29*/ property1; + +/*30*/ @ decorator33 @ decorator34 @decorator35 property2; +/*31*/function test(@decorator36@decorator37 param) {}; +/*32*/function test2(@decorator38()@decorator39()param) {}; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `@decorator1`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `@decorator2`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `@decorator3`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `@decorator4 @decorator5`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `class C {`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` @decorator6`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` @decorator7`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, ` @decorator8`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, ` method1() { }`) + f.GoToMarker(t, "10") + f.VerifyCurrentLineContent(t, ` @decorator9 @decorator10 @decorator11 method2() { }`) + f.GoToMarker(t, "11") + f.VerifyCurrentLineContent(t, ` @decorator12`) + f.GoToMarker(t, "12") + f.VerifyCurrentLineContent(t, ` @decorator13`) + f.GoToMarker(t, "13") + f.VerifyCurrentLineContent(t, ` @decorator14`) + f.GoToMarker(t, "14") + f.VerifyCurrentLineContent(t, ` x) { }`) + f.GoToMarker(t, "15") + f.VerifyCurrentLineContent(t, ` @decorator15 @decorator16 @decorator17 x) { }`) + f.GoToMarker(t, "16") + f.VerifyCurrentLineContent(t, ` @decorator18`) + f.GoToMarker(t, "17") + f.VerifyCurrentLineContent(t, ` @decorator19`) + f.GoToMarker(t, "18") + f.VerifyCurrentLineContent(t, ` @decorator20`) + f.GoToMarker(t, "19") + f.VerifyCurrentLineContent(t, ` ["computed1"]() { }`) + f.GoToMarker(t, "20") + f.VerifyCurrentLineContent(t, ` @decorator21 @decorator22 @decorator23 ["computed2"]() { }`) + f.GoToMarker(t, "21") + f.VerifyCurrentLineContent(t, ` @decorator24`) + f.GoToMarker(t, "22") + f.VerifyCurrentLineContent(t, ` @decorator25`) + f.GoToMarker(t, "23") + f.VerifyCurrentLineContent(t, ` @decorator26`) + f.GoToMarker(t, "24") + f.VerifyCurrentLineContent(t, ` get accessor1() { }`) + f.GoToMarker(t, "25") + f.VerifyCurrentLineContent(t, ` @decorator27 @decorator28 @decorator29 get accessor2() { }`) + f.GoToMarker(t, "26") + f.VerifyCurrentLineContent(t, ` @decorator30`) + f.GoToMarker(t, "27") + f.VerifyCurrentLineContent(t, ` @decorator31`) + f.GoToMarker(t, "28") + f.VerifyCurrentLineContent(t, ` @decorator32`) + f.GoToMarker(t, "29") + f.VerifyCurrentLineContent(t, ` property1;`) + f.GoToMarker(t, "30") + f.VerifyCurrentLineContent(t, ` @decorator33 @decorator34 @decorator35 property2;`) + f.GoToMarker(t, "31") + f.VerifyCurrentLineContent(t, `function test(@decorator36 @decorator37 param) { };`) + f.GoToMarker(t, "32") + f.VerifyCurrentLineContent(t, `function test2(@decorator38() @decorator39() param) { };`) +} diff --git a/internal/fourslash/tests/gen/formattingDoubleLessThan_test.go b/internal/fourslash/tests/gen/formattingDoubleLessThan_test.go new file mode 100644 index 0000000000..64bb47cf04 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingDoubleLessThan_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingDoubleLessThan(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/if (foo < bar) {}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `if (foo < bar) { }`) +} diff --git a/internal/fourslash/tests/gen/formattingElseInsideAFunction_test.go b/internal/fourslash/tests/gen/formattingElseInsideAFunction_test.go new file mode 100644 index 0000000000..50546bab71 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingElseInsideAFunction_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingElseInsideAFunction(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = function() { + if (true) { + /*1*/} else {/*2*/ +} + +// newline at the end of the file` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "2") + f.InsertLine(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` } else {`) +} diff --git a/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go b/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go new file mode 100644 index 0000000000..9969bedefa --- /dev/null +++ b/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingEqualsBeforeBracketInTypeAlias(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `type X = [number]/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, `type X = [number];`) +} diff --git a/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go b/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go new file mode 100644 index 0000000000..c147a0877c --- /dev/null +++ b/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingExpressionsInIfCondition(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if (a === 1 || + /*0*/b === 2 ||/*1*/ + c === 3) { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "\n") + f.GoToMarker(t, "0") + f.VerifyCurrentLineContent(t, ` b === 2 ||`) +} diff --git a/internal/fourslash/tests/gen/formattingFatArrowFunctions_test.go b/internal/fourslash/tests/gen/formattingFatArrowFunctions_test.go new file mode 100644 index 0000000000..5bd0a9771f --- /dev/null +++ b/internal/fourslash/tests/gen/formattingFatArrowFunctions_test.go @@ -0,0 +1,306 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingFatArrowFunctions(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// valid + ( ) => 1 ;/*1*/ + ( arg ) => 2 ;/*2*/ + arg => 2 ;/*3*/ + arg=>2 ;/*3a*/ + ( arg = 1 ) => 3 ;/*4*/ + ( arg ? ) => 4 ;/*5*/ + ( arg : number ) => 5 ;/*6*/ + ( arg : number = 0 ) => 6 ;/*7*/ + ( arg ? : number ) => 7 ;/*8*/ + ( ... arg : number [ ] ) => 8 ;/*9*/ + ( arg1 , arg2 ) => 12 ;/*10*/ + ( arg1 = 1 , arg2 =3 ) => 13 ;/*11*/ + ( arg1 ? , arg2 ? ) => 14 ;/*12*/ + ( arg1 : number , arg2 : number ) => 15 ;/*13*/ + ( arg1 : number = 0 , arg2 : number = 1 ) => 16 ;/*14*/ + ( arg1 ? : number , arg2 ? : number ) => 17 ;/*15*/ + ( arg1 , ... arg2 : number [ ] ) => 18 ;/*16*/ + ( arg1 , arg2 ? : number ) => 19 ;/*17*/ + +// in paren + ( ( ) => 21 ) ;/*18*/ + ( ( arg ) => 22 ) ;/*19*/ + ( ( arg = 1 ) => 23 ) ;/*20*/ + ( ( arg ? ) => 24 ) ;/*21*/ + ( ( arg : number ) => 25 ) ;/*22*/ + ( ( arg : number = 0 ) => 26 ) ;/*23*/ + ( ( arg ? : number ) => 27 ) ;/*24*/ + ( ( ... arg : number [ ] ) => 28 ) ;/*25*/ + +// in multiple paren + ( ( ( ( ( arg ) => { return 32 ; } ) ) ) ) ;/*26*/ + +// in ternary exression + false ? ( ) => 41 : null ;/*27*/ + false ? ( arg ) => 42 : null ;/*28*/ + false ? ( arg = 1 ) => 43 : null ;/*29*/ + false ? ( arg ? ) => 44 : null ;/*30*/ + false ? ( arg : number ) => 45 : null ;/*31*/ + false ? ( arg ? : number ) => 46 : null ;/*32*/ + false ? ( arg ? : number = 0 ) => 47 : null ;/*33*/ + false ? ( ... arg : number [ ] ) => 48 : null ;/*34*/ + +// in ternary exression within paren + false ? ( ( ) => 51 ) : null ;/*35*/ + false ? ( ( arg ) => 52 ) : null ;/*36*/ + false ? ( ( arg = 1 ) => 53 ) : null ;/*37*/ + false ? ( ( arg ? ) => 54 ) : null ;/*38*/ + false ? ( ( arg : number ) => 55 ) : null ;/*39*/ + false ? ( ( arg ? : number ) => 56 ) : null ;/*40*/ + false ? ( ( arg ? : number = 0 ) => 57 ) : null ;/*41*/ + false ? ( ( ... arg : number [ ] ) => 58 ) : null ;/*42*/ + +// ternary exression's else clause + false ? null : ( ) => 61 ;/*43*/ + false ? null : ( arg ) => 62 ;/*44*/ + false ? null : ( arg = 1 ) => 63 ;/*45*/ + false ? null : ( arg ? ) => 64 ;/*46*/ + false ? null : ( arg : number ) => 65 ;/*47*/ + false ? null : ( arg ? : number ) => 66 ;/*48*/ + false ? null : ( arg ? : number = 0 ) => 67 ;/*49*/ + false ? null : ( ... arg : number [ ] ) => 68 ;/*50*/ + + +// nested ternary expressions + (( a ? ) => { return a ; }) ? ( b ? ) => { return b ; } : ( c ? ) => { return c ; } ;/*51*/ + +//multiple levels + (( a ? ) => { return a ; }) ? ( b ) => ( c ) => 81 : ( c ) => ( d ) => 82 ;/*52*/ + + +// In Expressions + ( ( arg ) => 90 ) instanceof Function ;/*53*/ + ( ( arg = 1 ) => 91 ) instanceof Function ;/*54*/ + ( ( arg ? ) => 92 ) instanceof Function ;/*55*/ + ( ( arg : number ) => 93 ) instanceof Function ;/*56*/ + ( ( arg : number = 1 ) => 94 ) instanceof Function ;/*57*/ + ( ( arg ? : number ) => 95 ) instanceof Function ;/*58*/ + ( ( ... arg : number [ ] ) => 96 ) instanceof Function ;/*59*/ + +'' + (( arg ) => 100) ;/*60*/ + ( ( arg ) => 0 ) + '' + (( arg ) => 101) ;/*61*/ + ( ( arg = 1 ) => 0 ) + '' + (( arg = 2 ) => 102) ;/*62*/ + ( ( arg ? ) => 0 ) + '' + (( arg ? ) => 103) ;/*63*/ + ( ( arg : number ) => 0 ) + '' + (( arg : number ) => 104) ;/*64*/ + ( ( arg : number = 1 ) => 0 ) + '' + (( arg : number = 2 ) => 105) ;/*65*/ + ( ( arg ? : number ) => 0 ) + '' + (( arg ? : number ) => 106) ;/*66*/ + ( ( ... arg : number [ ] ) => 0 ) + '' + (( ... arg : number [ ] ) => 107) ;/*67*/ + ( ( arg1 , arg2 ? ) => 0 ) + '' + (( arg1 , arg2 ? ) => 108) ;/*68*/ + ( ( arg1 , ... arg2 : number [ ] ) => 0 ) + '' + (( arg1 , ... arg2 : number [ ] ) => 108) ;/*69*/ + + +// Function Parameters +/*70*/function foo ( ... arg : any [ ] ) { } + +/*71*/foo ( +/*72*/ ( a ) => 110 , +/*73*/ ( ( a ) => 111 ) , +/*74*/ ( a ) => { + return /*75*/112 ; +/*76*/ } , +/*77*/ ( a ? ) => 113 , +/*78*/ ( a , b ? ) => 114 , +/*79*/ ( a : number ) => 115 , +/*80*/ ( a : number = 0 ) => 116 , +/*81*/ ( a = 0 ) => 117 , +/*82*/ ( a : number = 0 ) => 118 , +/*83*/ ( a ? , b ? : number ) => 118 , +/*84*/ ( ... a : number [ ] ) => 119 , +/*85*/ ( a , b = 0 , ... c : number [ ] ) => 120 , +/*86*/ ( a ) => ( b ) => ( c ) => 121 , +/*87*/ false ? ( a ) => 0 : ( b ) => 122 + /*88*/) ;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `() => 1;`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `(arg) => 2;`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `arg => 2;`) + f.GoToMarker(t, "3a") + f.VerifyCurrentLineContent(t, `arg => 2;`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `(arg = 1) => 3;`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `(arg?) => 4;`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, `(arg: number) => 5;`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, `(arg: number = 0) => 6;`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, `(arg?: number) => 7;`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, `(...arg: number[]) => 8;`) + f.GoToMarker(t, "10") + f.VerifyCurrentLineContent(t, `(arg1, arg2) => 12;`) + f.GoToMarker(t, "11") + f.VerifyCurrentLineContent(t, `(arg1 = 1, arg2 = 3) => 13;`) + f.GoToMarker(t, "12") + f.VerifyCurrentLineContent(t, `(arg1?, arg2?) => 14;`) + f.GoToMarker(t, "13") + f.VerifyCurrentLineContent(t, `(arg1: number, arg2: number) => 15;`) + f.GoToMarker(t, "14") + f.VerifyCurrentLineContent(t, `(arg1: number = 0, arg2: number = 1) => 16;`) + f.GoToMarker(t, "15") + f.VerifyCurrentLineContent(t, `(arg1?: number, arg2?: number) => 17;`) + f.GoToMarker(t, "16") + f.VerifyCurrentLineContent(t, `(arg1, ...arg2: number[]) => 18;`) + f.GoToMarker(t, "17") + f.VerifyCurrentLineContent(t, `(arg1, arg2?: number) => 19;`) + f.GoToMarker(t, "18") + f.VerifyCurrentLineContent(t, `(() => 21);`) + f.GoToMarker(t, "19") + f.VerifyCurrentLineContent(t, `((arg) => 22);`) + f.GoToMarker(t, "20") + f.VerifyCurrentLineContent(t, `((arg = 1) => 23);`) + f.GoToMarker(t, "21") + f.VerifyCurrentLineContent(t, `((arg?) => 24);`) + f.GoToMarker(t, "22") + f.VerifyCurrentLineContent(t, `((arg: number) => 25);`) + f.GoToMarker(t, "23") + f.VerifyCurrentLineContent(t, `((arg: number = 0) => 26);`) + f.GoToMarker(t, "24") + f.VerifyCurrentLineContent(t, `((arg?: number) => 27);`) + f.GoToMarker(t, "25") + f.VerifyCurrentLineContent(t, `((...arg: number[]) => 28);`) + f.GoToMarker(t, "26") + f.VerifyCurrentLineContent(t, `(((((arg) => { return 32; }))));`) + f.GoToMarker(t, "27") + f.VerifyCurrentLineContent(t, `false ? () => 41 : null;`) + f.GoToMarker(t, "28") + f.VerifyCurrentLineContent(t, `false ? (arg) => 42 : null;`) + f.GoToMarker(t, "29") + f.VerifyCurrentLineContent(t, `false ? (arg = 1) => 43 : null;`) + f.GoToMarker(t, "30") + f.VerifyCurrentLineContent(t, `false ? (arg?) => 44 : null;`) + f.GoToMarker(t, "31") + f.VerifyCurrentLineContent(t, `false ? (arg: number) => 45 : null;`) + f.GoToMarker(t, "32") + f.VerifyCurrentLineContent(t, `false ? (arg?: number) => 46 : null;`) + f.GoToMarker(t, "33") + f.VerifyCurrentLineContent(t, `false ? (arg?: number = 0) => 47 : null;`) + f.GoToMarker(t, "34") + f.VerifyCurrentLineContent(t, `false ? (...arg: number[]) => 48 : null;`) + f.GoToMarker(t, "35") + f.VerifyCurrentLineContent(t, `false ? (() => 51) : null;`) + f.GoToMarker(t, "36") + f.VerifyCurrentLineContent(t, `false ? ((arg) => 52) : null;`) + f.GoToMarker(t, "37") + f.VerifyCurrentLineContent(t, `false ? ((arg = 1) => 53) : null;`) + f.GoToMarker(t, "38") + f.VerifyCurrentLineContent(t, `false ? ((arg?) => 54) : null;`) + f.GoToMarker(t, "39") + f.VerifyCurrentLineContent(t, `false ? ((arg: number) => 55) : null;`) + f.GoToMarker(t, "40") + f.VerifyCurrentLineContent(t, `false ? ((arg?: number) => 56) : null;`) + f.GoToMarker(t, "41") + f.VerifyCurrentLineContent(t, `false ? ((arg?: number = 0) => 57) : null;`) + f.GoToMarker(t, "42") + f.VerifyCurrentLineContent(t, `false ? ((...arg: number[]) => 58) : null;`) + f.GoToMarker(t, "43") + f.VerifyCurrentLineContent(t, `false ? null : () => 61;`) + f.GoToMarker(t, "44") + f.VerifyCurrentLineContent(t, `false ? null : (arg) => 62;`) + f.GoToMarker(t, "45") + f.VerifyCurrentLineContent(t, `false ? null : (arg = 1) => 63;`) + f.GoToMarker(t, "46") + f.VerifyCurrentLineContent(t, `false ? null : (arg?) => 64;`) + f.GoToMarker(t, "47") + f.VerifyCurrentLineContent(t, `false ? null : (arg: number) => 65;`) + f.GoToMarker(t, "48") + f.VerifyCurrentLineContent(t, `false ? null : (arg?: number) => 66;`) + f.GoToMarker(t, "49") + f.VerifyCurrentLineContent(t, `false ? null : (arg?: number = 0) => 67;`) + f.GoToMarker(t, "50") + f.VerifyCurrentLineContent(t, `false ? null : (...arg: number[]) => 68;`) + f.GoToMarker(t, "51") + f.VerifyCurrentLineContent(t, `((a?) => { return a; }) ? (b?) => { return b; } : (c?) => { return c; };`) + f.GoToMarker(t, "52") + f.VerifyCurrentLineContent(t, `((a?) => { return a; }) ? (b) => (c) => 81 : (c) => (d) => 82;`) + f.GoToMarker(t, "53") + f.VerifyCurrentLineContent(t, `((arg) => 90) instanceof Function;`) + f.GoToMarker(t, "54") + f.VerifyCurrentLineContent(t, `((arg = 1) => 91) instanceof Function;`) + f.GoToMarker(t, "55") + f.VerifyCurrentLineContent(t, `((arg?) => 92) instanceof Function;`) + f.GoToMarker(t, "56") + f.VerifyCurrentLineContent(t, `((arg: number) => 93) instanceof Function;`) + f.GoToMarker(t, "57") + f.VerifyCurrentLineContent(t, `((arg: number = 1) => 94) instanceof Function;`) + f.GoToMarker(t, "58") + f.VerifyCurrentLineContent(t, `((arg?: number) => 95) instanceof Function;`) + f.GoToMarker(t, "59") + f.VerifyCurrentLineContent(t, `((...arg: number[]) => 96) instanceof Function;`) + f.GoToMarker(t, "60") + f.VerifyCurrentLineContent(t, `'' + ((arg) => 100);`) + f.GoToMarker(t, "61") + f.VerifyCurrentLineContent(t, `((arg) => 0) + '' + ((arg) => 101);`) + f.GoToMarker(t, "62") + f.VerifyCurrentLineContent(t, `((arg = 1) => 0) + '' + ((arg = 2) => 102);`) + f.GoToMarker(t, "63") + f.VerifyCurrentLineContent(t, `((arg?) => 0) + '' + ((arg?) => 103);`) + f.GoToMarker(t, "64") + f.VerifyCurrentLineContent(t, `((arg: number) => 0) + '' + ((arg: number) => 104);`) + f.GoToMarker(t, "65") + f.VerifyCurrentLineContent(t, `((arg: number = 1) => 0) + '' + ((arg: number = 2) => 105);`) + f.GoToMarker(t, "66") + f.VerifyCurrentLineContent(t, `((arg?: number) => 0) + '' + ((arg?: number) => 106);`) + f.GoToMarker(t, "67") + f.VerifyCurrentLineContent(t, `((...arg: number[]) => 0) + '' + ((...arg: number[]) => 107);`) + f.GoToMarker(t, "68") + f.VerifyCurrentLineContent(t, `((arg1, arg2?) => 0) + '' + ((arg1, arg2?) => 108);`) + f.GoToMarker(t, "69") + f.VerifyCurrentLineContent(t, `((arg1, ...arg2: number[]) => 0) + '' + ((arg1, ...arg2: number[]) => 108);`) + f.GoToMarker(t, "70") + f.VerifyCurrentLineContent(t, `function foo(...arg: any[]) { }`) + f.GoToMarker(t, "71") + f.VerifyCurrentLineContent(t, `foo(`) + f.GoToMarker(t, "72") + f.VerifyCurrentLineContent(t, ` (a) => 110,`) + f.GoToMarker(t, "73") + f.VerifyCurrentLineContent(t, ` ((a) => 111),`) + f.GoToMarker(t, "74") + f.VerifyCurrentLineContent(t, ` (a) => {`) + f.GoToMarker(t, "75") + f.VerifyCurrentLineContent(t, ` return 112;`) + f.GoToMarker(t, "76") + f.VerifyCurrentLineContent(t, ` },`) + f.GoToMarker(t, "77") + f.VerifyCurrentLineContent(t, ` (a?) => 113,`) + f.GoToMarker(t, "78") + f.VerifyCurrentLineContent(t, ` (a, b?) => 114,`) + f.GoToMarker(t, "79") + f.VerifyCurrentLineContent(t, ` (a: number) => 115,`) + f.GoToMarker(t, "80") + f.VerifyCurrentLineContent(t, ` (a: number = 0) => 116,`) + f.GoToMarker(t, "81") + f.VerifyCurrentLineContent(t, ` (a = 0) => 117,`) + f.GoToMarker(t, "82") + f.VerifyCurrentLineContent(t, ` (a: number = 0) => 118,`) + f.GoToMarker(t, "83") + f.VerifyCurrentLineContent(t, ` (a?, b?: number) => 118,`) + f.GoToMarker(t, "84") + f.VerifyCurrentLineContent(t, ` (...a: number[]) => 119,`) + f.GoToMarker(t, "85") + f.VerifyCurrentLineContent(t, ` (a, b = 0, ...c: number[]) => 120,`) + f.GoToMarker(t, "86") + f.VerifyCurrentLineContent(t, ` (a) => (b) => (c) => 121,`) + f.GoToMarker(t, "87") + f.VerifyCurrentLineContent(t, ` false ? (a) => 0 : (b) => 122`) +} diff --git a/internal/fourslash/tests/gen/formattingForIn_test.go b/internal/fourslash/tests/gen/formattingForIn_test.go new file mode 100644 index 0000000000..8f6990677b --- /dev/null +++ b/internal/fourslash/tests/gen/formattingForIn_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingForIn(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/for (var i in[] ) {}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "") + f.VerifyCurrentLineContent(t, `for (var i in []) { }`) +} diff --git a/internal/fourslash/tests/gen/formattingForLoopSemicolons_test.go b/internal/fourslash/tests/gen/formattingForLoopSemicolons_test.go new file mode 100644 index 0000000000..69bd077ce4 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingForLoopSemicolons_test.go @@ -0,0 +1,34 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingForLoopSemicolons(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/for (;;) { } +/*2*/for (var x;x<0;x++) { } +/*3*/for (var x ;x<0 ;x++) { }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `for (; ;) { }`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `for (var x; x < 0; x++) { }`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `for (var x; x < 0; x++) { }`) + f.SetFormatOption(t, "InsertSpaceAfterSemicolonInForStatements", false) + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `for (;;) { }`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `for (var x;x < 0;x++) { }`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `for (var x;x < 0;x++) { }`) +} diff --git a/internal/fourslash/tests/gen/formattingForOfKeyword_test.go b/internal/fourslash/tests/gen/formattingForOfKeyword_test.go new file mode 100644 index 0000000000..761ca0f182 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingForOfKeyword_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingForOfKeyword(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/for ([]of[]) { }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "") + f.VerifyCurrentLineContent(t, `for ([] of []) { }`) +} diff --git a/internal/fourslash/tests/gen/formattingGlobalAugmentation1_test.go b/internal/fourslash/tests/gen/formattingGlobalAugmentation1_test.go new file mode 100644 index 0000000000..2ce50a9fb0 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingGlobalAugmentation1_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingGlobalAugmentation1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/declare global { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `declare global {`) +} diff --git a/internal/fourslash/tests/gen/formattingGlobalAugmentation2_test.go b/internal/fourslash/tests/gen/formattingGlobalAugmentation2_test.go new file mode 100644 index 0000000000..8e483a18eb --- /dev/null +++ b/internal/fourslash/tests/gen/formattingGlobalAugmentation2_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingGlobalAugmentation2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `declare module "A" { +/*1*/ global { + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` global {`) +} diff --git a/internal/fourslash/tests/gen/formattingHexLiteral_test.go b/internal/fourslash/tests/gen/formattingHexLiteral_test.go new file mode 100644 index 0000000000..bda553bd73 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingHexLiteral_test.go @@ -0,0 +1,18 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingHexLiteral(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = 0x1,y;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") +} diff --git a/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go b/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go new file mode 100644 index 0000000000..ead7072a38 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingIfInElseBlock(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if (true) { +} +else { + if (true) { + /*1*/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "}") + f.VerifyCurrentLineContent(t, ` }`) +} diff --git a/internal/fourslash/tests/gen/formattingIllegalImportClause_test.go b/internal/fourslash/tests/gen/formattingIllegalImportClause_test.go new file mode 100644 index 0000000000..7baa2f3b27 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingIllegalImportClause_test.go @@ -0,0 +1,35 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingIllegalImportClause(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var expect = require('expect.js'); +import React from 'react'/*1*/; +import { mount } from 'enzyme'; +require('../setup'); +var Amount = require('../../src/js/components/amount'); +describe('', () => { + var history + beforeEach(() => { + history = createMemoryHistory(); + sinon.spy(history, 'pushState'); + }); + afterEach(() => { + }) + it('redirects to order summary', () => { + }); +});` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `import React from 'react';`) +} diff --git a/internal/fourslash/tests/gen/formattingInComment_test.go b/internal/fourslash/tests/gen/formattingInComment_test.go new file mode 100644 index 0000000000..b1647208f4 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingInComment_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingInComment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class A { +foo( ); // /*1*/ +} +function foo() { var x; } // /*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, `foo( ); // ;`) + f.GoToMarker(t, "2") + f.Insert(t, "}") + f.VerifyCurrentLineContent(t, `function foo() { var x; } // }`) +} diff --git a/internal/fourslash/tests/gen/formattingInDestructuring1_test.go b/internal/fourslash/tests/gen/formattingInDestructuring1_test.go new file mode 100644 index 0000000000..16965cbe3c --- /dev/null +++ b/internal/fourslash/tests/gen/formattingInDestructuring1_test.go @@ -0,0 +1,35 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingInDestructuring1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface let { } +/*1*/var x: let []; + +function foo() { + 'use strict' +/*2*/ let [x] = []; +/*3*/ const [x] = []; +/*4*/ for (let[x] = [];x < 1;) { + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `var x: let[];`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` let [x] = [];`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` const [x] = [];`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` for (let [x] = []; x < 1;) {`) +} diff --git a/internal/fourslash/tests/gen/formattingInDestructuring2_test.go b/internal/fourslash/tests/gen/formattingInDestructuring2_test.go new file mode 100644 index 0000000000..f6c4e44f74 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingInDestructuring2_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingInDestructuring2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/function drawText( { text = "", location: [x, y]= [0, 0], bold = false }) { + // Draw text +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `function drawText({ text = "", location: [x, y] = [0, 0], bold = false }) {`) +} diff --git a/internal/fourslash/tests/gen/formattingInDestructuring3_test.go b/internal/fourslash/tests/gen/formattingInDestructuring3_test.go new file mode 100644 index 0000000000..b6fc116982 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingInDestructuring3_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingInDestructuring3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/const { +/*2*/ a, +/*3*/ b, +/*4*/} = {a: 1, b: 2}; +/*5*/const {a: c} = {a: 1, b: 2};` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `const {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` a,`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` b,`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `} = { a: 1, b: 2 };`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `const { a: c } = { a: 1, b: 2 };`) +} diff --git a/internal/fourslash/tests/gen/formattingInDestructuring4_test.go b/internal/fourslash/tests/gen/formattingInDestructuring4_test.go new file mode 100644 index 0000000000..a9a5a33383 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingInDestructuring4_test.go @@ -0,0 +1,30 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingInDestructuring4(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/const { +/*2*/ a, +/*3*/ b, +/*4*/} = { a: 1, b: 2 };` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces", false) + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `const {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` a,`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` b,`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `} = {a: 1, b: 2};`) +} diff --git a/internal/fourslash/tests/gen/formattingInDestructuring5_test.go b/internal/fourslash/tests/gen/formattingInDestructuring5_test.go new file mode 100644 index 0000000000..47073485cb --- /dev/null +++ b/internal/fourslash/tests/gen/formattingInDestructuring5_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingInDestructuring5(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let a, b; +/*1*/if (false)[a, b] = [1, 2]; +/*2*/if (true) [a, b] = [1, 2]; +/*3*/var a = [1, 2, 3].map(num => num) [0];` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `if (false) [a, b] = [1, 2];`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `if (true) [a, b] = [1, 2];`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `var a = [1, 2, 3].map(num => num)[0];`) +} diff --git a/internal/fourslash/tests/gen/formattingInExpressionsInTsx_test.go b/internal/fourslash/tests/gen/formattingInExpressionsInTsx_test.go new file mode 100644 index 0000000000..eea534c298 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingInExpressionsInTsx_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingInExpressionsInTsx(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: test.tsx +import * as React from "react"; +
+
` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, ` return true;`) +} diff --git a/internal/fourslash/tests/gen/formattingInMultilineComments_test.go b/internal/fourslash/tests/gen/formattingInMultilineComments_test.go new file mode 100644 index 0000000000..6c3b439c8e --- /dev/null +++ b/internal/fourslash/tests/gen/formattingInMultilineComments_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingInMultilineComments(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = function() { + if (true) { + /*1*/} else {/*2*/ +} + +// newline at the end of the file` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "2") + f.InsertLine(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` } else {`) +} diff --git a/internal/fourslash/tests/gen/formattingJsxTexts1_test.go b/internal/fourslash/tests/gen/formattingJsxTexts1_test.go new file mode 100644 index 0000000000..b97d8b621d --- /dev/null +++ b/internal/fourslash/tests/gen/formattingJsxTexts1_test.go @@ -0,0 +1,128 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingJsxTexts1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `//@Filename: file.tsx +;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `;`) +} diff --git a/internal/fourslash/tests/gen/formattingJsxTexts2_test.go b/internal/fourslash/tests/gen/formattingJsxTexts2_test.go new file mode 100644 index 0000000000..d808e5e16f --- /dev/null +++ b/internal/fourslash/tests/gen/formattingJsxTexts2_test.go @@ -0,0 +1,90 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingJsxTexts2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `//@Filename: file.tsx +const a = ( +
+ foo +
+); + +const b = ( +
+ { foo } +
+); + +const c = ( +
+ foo + { foobar } + bar +
+); + +const d = +
+ foo +
; + +const e = +
+ { foo } +
+ +const f = +
+ foo + { foobar } + bar +
` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `const a = ( +
+ foo +
+); + +const b = ( +
+ {foo} +
+); + +const c = ( +
+ foo + {foobar} + bar +
+); + +const d = +
+ foo +
; + +const e = +
+ {foo} +
+ +const f = +
+ foo + {foobar} + bar +
`) +} diff --git a/internal/fourslash/tests/gen/formattingJsxTexts3_test.go b/internal/fourslash/tests/gen/formattingJsxTexts3_test.go new file mode 100644 index 0000000000..5a3520763a --- /dev/null +++ b/internal/fourslash/tests/gen/formattingJsxTexts3_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingJsxTexts3(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `//@Filename: file.tsx +function foo() { +const bar = "Oh no"; + +return ( +
"{bar}"
+) +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `function foo() { + const bar = "Oh no"; + + return ( +
"{bar}"
+ ) +}`) +} diff --git a/internal/fourslash/tests/gen/formattingJsxTexts4_test.go b/internal/fourslash/tests/gen/formattingJsxTexts4_test.go new file mode 100644 index 0000000000..7f61b0be73 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingJsxTexts4_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingJsxTexts4(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `//@Filename: file.tsx +function foo() { +const a = ; + +return a; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `function foo() { + const a = ; + + return a; +}`) +} diff --git a/internal/fourslash/tests/gen/formattingKeywordAsIdentifier_test.go b/internal/fourslash/tests/gen/formattingKeywordAsIdentifier_test.go new file mode 100644 index 0000000000..236b392093 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingKeywordAsIdentifier_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingKeywordAsIdentifier(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `declare var module/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, `declare var module;`) +} diff --git a/internal/fourslash/tests/gen/formattingMappedType_test.go b/internal/fourslash/tests/gen/formattingMappedType_test.go new file mode 100644 index 0000000000..918f6872c4 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingMappedType_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingMappedType(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*generic*/type t < T > = { +/*map*/ [ P in keyof T ] : T [ P ] +};` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "generic") + f.VerifyCurrentLineContent(t, `type t = {`) + f.GoToMarker(t, "map") + f.VerifyCurrentLineContent(t, ` [P in keyof T]: T[P]`) +} diff --git a/internal/fourslash/tests/gen/formattingMultilineCommentsWithTabs1_test.go b/internal/fourslash/tests/gen/formattingMultilineCommentsWithTabs1_test.go new file mode 100644 index 0000000000..46e7b91ea0 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingMultilineCommentsWithTabs1_test.go @@ -0,0 +1,42 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingMultilineCommentsWithTabs1(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var f = function (j) { + + switch (j) { + case 1: +/*1*/ /* when current checkbox has focus, Firefox has changed check state already +/*2*/ on SPACE bar press only +/*3*/ IE does not have issue, use the CSS class +/*4*/ input:focus[type=checkbox] (z-index = 31290) +/*5*/ to determine whether checkbox has focus or not + */ + break; + case 2: + break; + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` /* when current checkbox has focus, Firefox has changed check state already`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` on SPACE bar press only`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` IE does not have issue, use the CSS class`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` input:focus[type=checkbox] (z-index = 31290)`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` to determine whether checkbox has focus or not`) +} diff --git a/internal/fourslash/tests/gen/formattingMultilineTemplateLiterals_test.go b/internal/fourslash/tests/gen/formattingMultilineTemplateLiterals_test.go new file mode 100644 index 0000000000..4c95d6d1cd --- /dev/null +++ b/internal/fourslash/tests/gen/formattingMultilineTemplateLiterals_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingMultilineTemplateLiterals(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/new Error(` + "`" + `Failed to expand glob: ${projectSpec.filesGlob} +/*2*/ at projectPath : ${projectFile} +/*3*/ with error: ${ex.message}` + "`" + `)` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, "new Error(`Failed to expand glob: ${projectSpec.filesGlob}") + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` at projectPath : ${projectFile}`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, " with error: ${ex.message}`)") +} diff --git a/internal/fourslash/tests/gen/formattingNestedScopes_test.go b/internal/fourslash/tests/gen/formattingNestedScopes_test.go new file mode 100644 index 0000000000..2c135d0cfc --- /dev/null +++ b/internal/fourslash/tests/gen/formattingNestedScopes_test.go @@ -0,0 +1,38 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingNestedScopes(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/ module My.App { +/*2*/export var appModule = angular.module("app", [ +/*3*/ ]).config([() => { +/*4*/ configureStates +/*5*/($stateProvider); +/*6*/}]).run(My.App.setup); +/*7*/ }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `module My.App {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` export var appModule = angular.module("app", [`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` ]).config([() => {`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` configureStates`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` ($stateProvider);`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` }]).run(My.App.setup);`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, `}`) +} diff --git a/internal/fourslash/tests/gen/formattingNonNullAssertionOperator_test.go b/internal/fourslash/tests/gen/formattingNonNullAssertionOperator_test.go new file mode 100644 index 0000000000..f036e4a473 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingNonNullAssertionOperator_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingNonNullAssertionOperator(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/ 'bar' ! ; +/*2*/ ( 'bar' ) ! ; +/*3*/ 'bar' [ 1 ] ! ; +/*4*/ var bar = 'bar' . foo ! ; +/*5*/ var foo = bar ! ;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `'bar'!;`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `('bar')!;`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `'bar'[1]!;`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `var bar = 'bar'.foo!;`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `var foo = bar!;`) +} diff --git a/internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlyNewlineAssignment_test.go b/internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlyNewlineAssignment_test.go new file mode 100644 index 0000000000..c19ca376d5 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlyNewlineAssignment_test.go @@ -0,0 +1,55 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingObjectLiteralOpenCurlyNewlineAssignment(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +var obj = {}; +obj = +{ + prop: 3 +}; + +var obj2 = obj || +{ + prop: 0 +} +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, ` +var obj = {}; +obj = +{ + prop: 3 +}; + +var obj2 = obj || +{ + prop: 0 +} +`) + f.SetFormatOption(t, "indentMultiLineObjectLiteralBeginningOnBlankLine", true) + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, ` +var obj = {}; +obj = + { + prop: 3 + }; + +var obj2 = obj || + { + prop: 0 + } +`) +} diff --git a/internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlyNewlineTyping_test.go b/internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlyNewlineTyping_test.go new file mode 100644 index 0000000000..9b58273b24 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlyNewlineTyping_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingObjectLiteralOpenCurlyNewlineTyping(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +var varName =/**/ +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "\n{") + f.VerifyCurrentFileContent(t, ` +var varName = + { +`) + f.Insert(t, "\na: 1") + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, ` +var varName = +{ + a: 1 +`) + f.Insert(t, "\n};") + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, ` +var varName = +{ + a: 1 +}; +`) +} diff --git a/internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlyNewline_test.go b/internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlyNewline_test.go new file mode 100644 index 0000000000..8ef1aab59d --- /dev/null +++ b/internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlyNewline_test.go @@ -0,0 +1,52 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingObjectLiteralOpenCurlyNewline(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +var clear = +{ + outerKey: + { + innerKey: 1, + innerKey2: + 2 + } +}; +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, ` +var clear = +{ + outerKey: + { + innerKey: 1, + innerKey2: + 2 + } +}; +`) + f.SetFormatOption(t, "indentMultiLineObjectLiteralBeginningOnBlankLine", true) + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, ` +var clear = + { + outerKey: + { + innerKey: 1, + innerKey2: + 2 + } + }; +`) +} diff --git a/internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlySingleLine_test.go b/internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlySingleLine_test.go new file mode 100644 index 0000000000..095d3f4ee7 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingObjectLiteralOpenCurlySingleLine_test.go @@ -0,0 +1,33 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingObjectLiteralOpenCurlySingleLine(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +let obj1 = +{ x: 10 }; + +let obj2 = + // leading trivia +{ y: 10 }; +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, ` +let obj1 = + { x: 10 }; + +let obj2 = + // leading trivia + { y: 10 }; +`) +} diff --git a/internal/fourslash/tests/gen/formattingObjectLiteral_test.go b/internal/fourslash/tests/gen/formattingObjectLiteral_test.go new file mode 100644 index 0000000000..f3f384ba91 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingObjectLiteral_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingObjectLiteral(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var clear = { +"a": 1/**/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "") + f.VerifyCurrentLineContent(t, ` "a": 1`) +} diff --git a/internal/fourslash/tests/gen/formattingOfChainedLambda_test.go b/internal/fourslash/tests/gen/formattingOfChainedLambda_test.go new file mode 100644 index 0000000000..f4f671a044 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOfChainedLambda_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOfChainedLambda(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var fn = (x: string) => ()=> alert(x)/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, `var fn = (x: string) => () => alert(x);`) +} diff --git a/internal/fourslash/tests/gen/formattingOfExportDefault_test.go b/internal/fourslash/tests/gen/formattingOfExportDefault_test.go new file mode 100644 index 0000000000..a178be5bab --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOfExportDefault_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOfExportDefault(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module Foo { +/*1*/ export default class Test { } +} +/*2*/export default function bar() { }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` export default class Test { }`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `export default function bar() { }`) +} diff --git a/internal/fourslash/tests/gen/formattingOfMultilineBlockConstructs_test.go b/internal/fourslash/tests/gen/formattingOfMultilineBlockConstructs_test.go new file mode 100644 index 0000000000..bf6b44250b --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOfMultilineBlockConstructs_test.go @@ -0,0 +1,81 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOfMultilineBlockConstructs(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module InternalModule/*1*/ +{ +} +interface MyInterface/*2*/ +{ +} +enum E/*3*/ +{ +} +class MyClass/*4*/ +{ +constructor()/*cons*/ +{ } + public MyFunction()/*5*/ + { + return 0; + } +public get Getter()/*6*/ +{ +} +public set Setter(x)/*7*/ +{ +} +} +function foo()/*8*/ +{ +{}/*9*/ +} +(function()/*10*/ +{ +}); +(() =>/*11*/ +{ +}); +var x :/*12*/ +{};/*13*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `module InternalModule {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `interface MyInterface {`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `enum E {`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `class MyClass {`) + f.GoToMarker(t, "cons") + f.VerifyCurrentLineContent(t, ` constructor() { }`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` public MyFunction() {`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` public get Getter() {`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` public set Setter(x) {`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, `function foo() {`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, ` { }`) + f.GoToMarker(t, "10") + f.VerifyCurrentLineContent(t, `(function() {`) + f.GoToMarker(t, "11") + f.VerifyCurrentLineContent(t, `(() => {`) + f.GoToMarker(t, "12") + f.VerifyCurrentLineContent(t, `var x:`) + f.GoToMarker(t, "13") + f.VerifyCurrentLineContent(t, ` {};`) +} diff --git a/internal/fourslash/tests/gen/formattingOnChainedCallbacksAndPropertyAccesses_test.go b/internal/fourslash/tests/gen/formattingOnChainedCallbacksAndPropertyAccesses_test.go new file mode 100644 index 0000000000..1f562355e7 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnChainedCallbacksAndPropertyAccesses_test.go @@ -0,0 +1,46 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnChainedCallbacksAndPropertyAccesses(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = 1; +x +/*1*/.toFixed +x +/*2*/.toFixed() +x +/*3*/.toFixed() +/*4*/.length +/*5*/.toString(); +x +/*6*/.toFixed +/*7*/.toString() +/*8*/.length;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` .toFixed`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` .toFixed()`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` .toFixed()`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` .length`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` .toString();`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` .toFixed`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` .toString()`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, ` .length;`) +} diff --git a/internal/fourslash/tests/gen/formattingOnClasses_test.go b/internal/fourslash/tests/gen/formattingOnClasses_test.go new file mode 100644 index 0000000000..ccb3a05718 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnClasses_test.go @@ -0,0 +1,233 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnClasses(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/ class a { +/*2*/ constructor ( n : number ) ; +/*3*/ constructor ( s : string ) ; +/*4*/ constructor ( ns : any ) { + +/*5*/ } + +/*6*/ public pgF ( ) { } + +/*7*/ public pv ; +/*8*/ public get d ( ) { +/*9*/ return 30 ; +/*10*/ } +/*11*/ public set d ( number ) { +/*12*/ } + +/*13*/ public static get p2 ( ) { +/*14*/ return { x : 30 , y : 40 } ; +/*15*/ } + +/*16*/ private static d2 ( ) { +/*17*/ } +/*18*/ private static get p3 ( ) { +/*19*/ return "string" ; +/*20*/ } +/*21*/ private pv3 ; + +/*22*/ private foo ( n : number ) : string ; +/*23*/ private foo ( s : string ) : string ; +/*24*/ private foo ( ns : any ) { +/*25*/ return ns.toString ( ) ; +/*26*/ } +/*27*/} + +/*28*/ class b extends a { +/*29*/} + +/*30*/ class m1b { + +/*31*/} + +/*32*/ interface m1ib { + +/*33*/ } +/*34*/ class c extends m1b { +/*35*/} + +/*36*/ class ib2 implements m1ib { +/*37*/} + +/*38*/ declare class aAmbient { +/*39*/ constructor ( n : number ) ; +/*40*/ constructor ( s : string ) ; +/*41*/ public pgF ( ) : void ; +/*42*/ public pv ; +/*43*/ public d : number ; +/*44*/ static p2 : { x : number ; y : number ; } ; +/*45*/ static d2 ( ) ; +/*46*/ static p3 ; +/*47*/ private pv3 ; +/*48*/ private foo ( s ) ; +/*49*/} + +/*50*/ class d { +/*51*/ private foo ( n : number ) : string ; +/*52*/ private foo ( s : string ) : string ; +/*53*/ private foo ( ns : any ) { +/*54*/ return ns.toString ( ) ; +/*55*/ } +/*56*/} + +/*57*/ class e { +/*58*/ private foo ( s : string ) : string ; +/*59*/ private foo ( n : number ) : string ; +/*60*/ private foo ( ns : any ) { +/*61*/ return ns.toString ( ) ; +/*62*/ } +/*63*/ protected bar ( ) { } +/*64*/ protected static bar2 ( ) { } +/*65*/ private pv4 : number = +/*66*/ {}; +/*END*/}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `class a {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` constructor(n: number);`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` constructor(s: string);`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` constructor(ns: any) {`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` public pgF() { }`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` public pv;`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, ` public get d() {`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, ` return 30;`) + f.GoToMarker(t, "10") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "11") + f.VerifyCurrentLineContent(t, ` public set d(number) {`) + f.GoToMarker(t, "12") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "13") + f.VerifyCurrentLineContent(t, ` public static get p2() {`) + f.GoToMarker(t, "14") + f.VerifyCurrentLineContent(t, ` return { x: 30, y: 40 };`) + f.GoToMarker(t, "15") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "16") + f.VerifyCurrentLineContent(t, ` private static d2() {`) + f.GoToMarker(t, "17") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "18") + f.VerifyCurrentLineContent(t, ` private static get p3() {`) + f.GoToMarker(t, "19") + f.VerifyCurrentLineContent(t, ` return "string";`) + f.GoToMarker(t, "20") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "21") + f.VerifyCurrentLineContent(t, ` private pv3;`) + f.GoToMarker(t, "22") + f.VerifyCurrentLineContent(t, ` private foo(n: number): string;`) + f.GoToMarker(t, "23") + f.VerifyCurrentLineContent(t, ` private foo(s: string): string;`) + f.GoToMarker(t, "24") + f.VerifyCurrentLineContent(t, ` private foo(ns: any) {`) + f.GoToMarker(t, "25") + f.VerifyCurrentLineContent(t, ` return ns.toString();`) + f.GoToMarker(t, "26") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "27") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "28") + f.VerifyCurrentLineContent(t, `class b extends a {`) + f.GoToMarker(t, "29") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "30") + f.VerifyCurrentLineContent(t, `class m1b {`) + f.GoToMarker(t, "31") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "32") + f.VerifyCurrentLineContent(t, `interface m1ib {`) + f.GoToMarker(t, "33") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "34") + f.VerifyCurrentLineContent(t, `class c extends m1b {`) + f.GoToMarker(t, "35") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "36") + f.VerifyCurrentLineContent(t, `class ib2 implements m1ib {`) + f.GoToMarker(t, "37") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "38") + f.VerifyCurrentLineContent(t, `declare class aAmbient {`) + f.GoToMarker(t, "39") + f.VerifyCurrentLineContent(t, ` constructor(n: number);`) + f.GoToMarker(t, "40") + f.VerifyCurrentLineContent(t, ` constructor(s: string);`) + f.GoToMarker(t, "41") + f.VerifyCurrentLineContent(t, ` public pgF(): void;`) + f.GoToMarker(t, "42") + f.VerifyCurrentLineContent(t, ` public pv;`) + f.GoToMarker(t, "43") + f.VerifyCurrentLineContent(t, ` public d: number;`) + f.GoToMarker(t, "44") + f.VerifyCurrentLineContent(t, ` static p2: { x: number; y: number; };`) + f.GoToMarker(t, "45") + f.VerifyCurrentLineContent(t, ` static d2();`) + f.GoToMarker(t, "46") + f.VerifyCurrentLineContent(t, ` static p3;`) + f.GoToMarker(t, "47") + f.VerifyCurrentLineContent(t, ` private pv3;`) + f.GoToMarker(t, "48") + f.VerifyCurrentLineContent(t, ` private foo(s);`) + f.GoToMarker(t, "49") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "50") + f.VerifyCurrentLineContent(t, `class d {`) + f.GoToMarker(t, "51") + f.VerifyCurrentLineContent(t, ` private foo(n: number): string;`) + f.GoToMarker(t, "52") + f.VerifyCurrentLineContent(t, ` private foo(s: string): string;`) + f.GoToMarker(t, "53") + f.VerifyCurrentLineContent(t, ` private foo(ns: any) {`) + f.GoToMarker(t, "54") + f.VerifyCurrentLineContent(t, ` return ns.toString();`) + f.GoToMarker(t, "55") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "56") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "57") + f.VerifyCurrentLineContent(t, `class e {`) + f.GoToMarker(t, "58") + f.VerifyCurrentLineContent(t, ` private foo(s: string): string;`) + f.GoToMarker(t, "59") + f.VerifyCurrentLineContent(t, ` private foo(n: number): string;`) + f.GoToMarker(t, "60") + f.VerifyCurrentLineContent(t, ` private foo(ns: any) {`) + f.GoToMarker(t, "61") + f.VerifyCurrentLineContent(t, ` return ns.toString();`) + f.GoToMarker(t, "62") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "63") + f.VerifyCurrentLineContent(t, ` protected bar() { }`) + f.GoToMarker(t, "64") + f.VerifyCurrentLineContent(t, ` protected static bar2() { }`) + f.GoToMarker(t, "65") + f.VerifyCurrentLineContent(t, ` private pv4: number =`) + f.GoToMarker(t, "66") + f.VerifyCurrentLineContent(t, ` {};`) + f.GoToMarker(t, "END") + f.VerifyCurrentLineContent(t, `}`) +} diff --git a/internal/fourslash/tests/gen/formattingOnCloseBrace_test.go b/internal/fourslash/tests/gen/formattingOnCloseBrace_test.go new file mode 100644 index 0000000000..29e797d4b1 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnCloseBrace_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnCloseBrace(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class foo { + /**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "}") + f.GoToBOF(t) + f.VerifyCurrentLineContent(t, `class foo {`) +} diff --git a/internal/fourslash/tests/gen/formattingOnClosingBracket_test.go b/internal/fourslash/tests/gen/formattingOnClosingBracket_test.go new file mode 100644 index 0000000000..9291df22b7 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnClosingBracket_test.go @@ -0,0 +1,104 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnClosingBracket(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function f( ) {/*1*/ +var x = 3;/*2*/ + var z = 2 ;/*3*/ + a = z ++ - 2 * x ;/*4*/ + for ( ; ; ) {/*5*/ + a+=(g +g)*a%t;/*6*/ + b -- ;/*7*/ +}/*8*/ + + switch ( a )/*9*/ + { + case 1 : {/*10*/ + a ++ ;/*11*/ + b--;/*12*/ + if(a===a)/*13*/ + return;/*14*/ + else/*15*/ + { + for(a in b)/*16*/ + if(a!=a)/*17*/ + { + for(a in b)/*18*/ + { +a++;/*19*/ + }/*20*/ + }/*21*/ + }/*22*/ + }/*23*/ + default:/*24*/ + break;/*25*/ + }/*26*/ +}/*27*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "InsertSpaceAfterSemicolonInForStatements", true) + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `function f() {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` var x = 3;`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` var z = 2;`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` a = z++ - 2 * x;`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` for (; ;) {`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` a += (g + g) * a % t;`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` b--;`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, ` switch (a) {`) + f.GoToMarker(t, "10") + f.VerifyCurrentLineContent(t, ` case 1: {`) + f.GoToMarker(t, "11") + f.VerifyCurrentLineContent(t, ` a++;`) + f.GoToMarker(t, "12") + f.VerifyCurrentLineContent(t, ` b--;`) + f.GoToMarker(t, "13") + f.VerifyCurrentLineContent(t, ` if (a === a)`) + f.GoToMarker(t, "14") + f.VerifyCurrentLineContent(t, ` return;`) + f.GoToMarker(t, "15") + f.VerifyCurrentLineContent(t, ` else {`) + f.GoToMarker(t, "16") + f.VerifyCurrentLineContent(t, ` for (a in b)`) + f.GoToMarker(t, "17") + f.VerifyCurrentLineContent(t, ` if (a != a) {`) + f.GoToMarker(t, "18") + f.VerifyCurrentLineContent(t, ` for (a in b) {`) + f.GoToMarker(t, "19") + f.VerifyCurrentLineContent(t, ` a++;`) + f.GoToMarker(t, "20") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "21") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "22") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "23") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "24") + f.VerifyCurrentLineContent(t, ` default:`) + f.GoToMarker(t, "25") + f.VerifyCurrentLineContent(t, ` break;`) + f.GoToMarker(t, "26") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "27") + f.VerifyCurrentLineContent(t, `}`) +} diff --git a/internal/fourslash/tests/gen/formattingOnCommaOperator_test.go b/internal/fourslash/tests/gen/formattingOnCommaOperator_test.go new file mode 100644 index 0000000000..fd7082889e --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnCommaOperator_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnCommaOperator(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var v1 = ((1, 2, 3), 4, 5, (6, 7));/*1*/ +function f1() { + var a = 1; + return a, v1, a;/*2*/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `var v1 = ((1, 2, 3), 4, 5, (6, 7));`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` return a, v1, a;`) +} diff --git a/internal/fourslash/tests/gen/formattingOnConstructorSignature_test.go b/internal/fourslash/tests/gen/formattingOnConstructorSignature_test.go new file mode 100644 index 0000000000..70de19ff44 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnConstructorSignature_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnConstructorSignature(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/interface Gourai { new () {} } +/*2*/type Stylet = { new () {} }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `interface Gourai { new() { } }`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `type Stylet = { new() { } }`) +} diff --git a/internal/fourslash/tests/gen/formattingOnDoWhileNoSemicolon_test.go b/internal/fourslash/tests/gen/formattingOnDoWhileNoSemicolon_test.go new file mode 100644 index 0000000000..ee7a8fbe81 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnDoWhileNoSemicolon_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnDoWhileNoSemicolon(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*2*/do { +/*3*/ for (var i = 0; i < 10; i++) +/*4*/ i -= 2 +/*5*/ }/*1*/while (1 !== 1)` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "\n") + f.VerifyCurrentLineContent(t, `while (1 !== 1)`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `do {`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` for (var i = 0; i < 10; i++)`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` i -= 2`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `}`) +} diff --git a/internal/fourslash/tests/gen/formattingOnDocumentReadyFunction_test.go b/internal/fourslash/tests/gen/formattingOnDocumentReadyFunction_test.go new file mode 100644 index 0000000000..685ed9f904 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnDocumentReadyFunction_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnDocumentReadyFunction(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/$ ( document ) . ready ( function ( ) { +/*2*/ alert ( 'i am ready' ) ; +/*3*/ } );` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `$(document).ready(function() {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` alert('i am ready');`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `});`) +} diff --git a/internal/fourslash/tests/gen/formattingOnEmptyInterfaceLiteral_test.go b/internal/fourslash/tests/gen/formattingOnEmptyInterfaceLiteral_test.go new file mode 100644 index 0000000000..f73eb3b5df --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnEmptyInterfaceLiteral_test.go @@ -0,0 +1,39 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnEmptyInterfaceLiteral(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/ function foo ( x : { } ) { } + +/*2*/foo ( { } ) ; + + + +/*3*/ interface bar { +/*4*/ x : { } ; +/*5*/ y : ( ) => { } ; +/*6*/ }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `function foo(x: {}) { }`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `foo({});`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `interface bar {`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` x: {};`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` y: () => {};`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, `}`) +} diff --git a/internal/fourslash/tests/gen/formattingOnEnterInComments_test.go b/internal/fourslash/tests/gen/formattingOnEnterInComments_test.go new file mode 100644 index 0000000000..0c8c2d6766 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnEnterInComments_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnEnterInComments(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module me { + class A { + /* + */*1*/ + /*2*/} +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.InsertLine(t, "") + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` }`) +} diff --git a/internal/fourslash/tests/gen/formattingOnEnterInStrings_test.go b/internal/fourslash/tests/gen/formattingOnEnterInStrings_test.go new file mode 100644 index 0000000000..f8dafa737b --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnEnterInStrings_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnEnterInStrings(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = /*1*/"unclosed string literal\/*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "2") + f.InsertLine(t, "") + f.InsertLine(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, "var x = \"unclosed string literal\\") +} diff --git a/internal/fourslash/tests/gen/formattingOnEnter_test.go b/internal/fourslash/tests/gen/formattingOnEnter_test.go new file mode 100644 index 0000000000..f3f4cf2e0e --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnEnter_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnEnter(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class foo { } +class bar {/**/ } +// new line here` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.InsertLine(t, "") + f.VerifyCurrentFileContent(t, `class foo { } +class bar { +} +// new line here`) +} diff --git a/internal/fourslash/tests/gen/formattingOnInterfaces_test.go b/internal/fourslash/tests/gen/formattingOnInterfaces_test.go new file mode 100644 index 0000000000..e1074fe478 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnInterfaces_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnInterfaces(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/interface Blah +{ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `interface Blah {`) +} diff --git a/internal/fourslash/tests/gen/formattingOnInvalidCodes_test.go b/internal/fourslash/tests/gen/formattingOnInvalidCodes_test.go new file mode 100644 index 0000000000..5ad7b3ed3e --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnInvalidCodes_test.go @@ -0,0 +1,281 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnInvalidCodes(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/var a;var c , b;var $d +/*2*/var $e +/*3*/var f +/*4*/a++;b++; + +/*5*/function f ( ) { +/*6*/ for (i = 0; i < 10; i++) { +/*7*/ k = abc + 123 ^ d; +/*8*/ a = XYZ[m (a[b[c][d]])]; +/*9*/ break; + +/*10*/ switch ( variable){ +/*11*/ case 1: abc += 425; +/*12*/break; +/*13*/case 404 : a [x--/2]%=3 ; +/*14*/ break ; +/*15*/ case vari : v[--x ] *=++y*( m + n / k[z]); +/*16*/ for (a in b){ +/*17*/ for (a = 0; a < 10; ++a) { +/*18*/ a++;--a; +/*19*/ if (a == b) { +/*20*/ a++;b--; +/*21*/ } +/*22*/else +/*23*/if (a == c){ +/*24*/++a; +/*25*/(--c)+=d; +/*26*/$c = $a + --$b; +/*27*/} +/*28*/if (a == b) +/*29*/if (a != b) { +/*30*/ if (a !== b) +/*31*/ if (a === b) +/*32*/ --a; +/*33*/ else +/*34*/ --a; +/*35*/ else { +/*36*/ a--;++b; +/*37*/a++ +/*38*/ } +/*39*/ } +/*40*/ } +/*41*/ for (x in y) { +/*42*/m-=m; +/*43*/k=1+2+3+4; +/*44*/} +/*45*/} +/*46*/ break; + +/*47*/ } +/*48*/ } +/*49*/ var a ={b:function(){}}; +/*50*/ return {a:1,b:2} +/*51*/} + +/*52*/var z = 1; +/*53*/ for (i = 0; i < 10; i++) +/*54*/ for (j = 0; j < 10; j++) +/*55*/for (k = 0; k < 10; ++k) { +/*56*/z++; +/*57*/} + +/*58*/for (k = 0; k < 10; k += 2) { +/*59*/z++; +/*60*/} + +/*61*/ $(document).ready (); + + +/*62*/ function pageLoad() { +/*63*/ $('#TextBox1' ) . unbind ( ) ; +/*64*/$('#TextBox1' ) . datepicker ( ) ; +/*65*/} + +/*66*/ function pageLoad ( ) { +/*67*/ var webclass=[ +/*68*/ { 'student' :/*69*/ +/*70*/ { 'id': '1', 'name': 'Linda Jones', 'legacySkill': 'Access, VB 5.0' } +/*71*/ } , +/*72*/{ 'student':/*73*/ +/*74*/{'id':'2','name':'Adam Davidson','legacySkill':'Cobol,MainFrame'} +/*75*/} , +/*76*/ { 'student':/*77*/ +/*78*/{ 'id':'3','name':'Charles Boyer' ,'legacySkill':'HTML, XML'} +/*79*/} +/*80*/ ]; + +/*81*/$create(Sys.UI.DataView,{data:webclass},null,null,$get('SList')); + +/*82*/} + +/*83*/$( document ).ready(function(){ +/*84*/alert('hello'); +/*85*/ } ) ;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `var a; var c, b; var $d`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `var $e`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `var f`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `a++; b++;`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `function f() {`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` for (i = 0; i < 10; i++) {`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` k = abc + 123 ^ d;`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, ` a = XYZ[m(a[b[c][d]])];`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, ` break;`) + f.GoToMarker(t, "10") + f.VerifyCurrentLineContent(t, ` switch (variable) {`) + f.GoToMarker(t, "11") + f.VerifyCurrentLineContent(t, ` case 1: abc += 425;`) + f.GoToMarker(t, "12") + f.VerifyCurrentLineContent(t, ` break;`) + f.GoToMarker(t, "13") + f.VerifyCurrentLineContent(t, ` case 404: a[x-- / 2] %= 3;`) + f.GoToMarker(t, "14") + f.VerifyCurrentLineContent(t, ` break;`) + f.GoToMarker(t, "15") + f.VerifyCurrentLineContent(t, ` case vari: v[--x] *= ++y * (m + n / k[z]);`) + f.GoToMarker(t, "16") + f.VerifyCurrentLineContent(t, ` for (a in b) {`) + f.GoToMarker(t, "17") + f.VerifyCurrentLineContent(t, ` for (a = 0; a < 10; ++a) {`) + f.GoToMarker(t, "18") + f.VerifyCurrentLineContent(t, ` a++; --a;`) + f.GoToMarker(t, "19") + f.VerifyCurrentLineContent(t, ` if (a == b) {`) + f.GoToMarker(t, "20") + f.VerifyCurrentLineContent(t, ` a++; b--;`) + f.GoToMarker(t, "21") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "22") + f.VerifyCurrentLineContent(t, ` else`) + f.GoToMarker(t, "23") + f.VerifyCurrentLineContent(t, ` if (a == c) {`) + f.GoToMarker(t, "24") + f.VerifyCurrentLineContent(t, ` ++a;`) + f.GoToMarker(t, "25") + f.VerifyCurrentLineContent(t, ` (--c) += d;`) + f.GoToMarker(t, "26") + f.VerifyCurrentLineContent(t, ` $c = $a + --$b;`) + f.GoToMarker(t, "27") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "28") + f.VerifyCurrentLineContent(t, ` if (a == b)`) + f.GoToMarker(t, "29") + f.VerifyCurrentLineContent(t, ` if (a != b) {`) + f.GoToMarker(t, "30") + f.VerifyCurrentLineContent(t, ` if (a !== b)`) + f.GoToMarker(t, "31") + f.VerifyCurrentLineContent(t, ` if (a === b)`) + f.GoToMarker(t, "32") + f.VerifyCurrentLineContent(t, ` --a;`) + f.GoToMarker(t, "33") + f.VerifyCurrentLineContent(t, ` else`) + f.GoToMarker(t, "34") + f.VerifyCurrentLineContent(t, ` --a;`) + f.GoToMarker(t, "35") + f.VerifyCurrentLineContent(t, ` else {`) + f.GoToMarker(t, "36") + f.VerifyCurrentLineContent(t, ` a--; ++b;`) + f.GoToMarker(t, "37") + f.VerifyCurrentLineContent(t, ` a++`) + f.GoToMarker(t, "38") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "39") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "40") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "41") + f.VerifyCurrentLineContent(t, ` for (x in y) {`) + f.GoToMarker(t, "42") + f.VerifyCurrentLineContent(t, ` m -= m;`) + f.GoToMarker(t, "43") + f.VerifyCurrentLineContent(t, ` k = 1 + 2 + 3 + 4;`) + f.GoToMarker(t, "44") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "45") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "46") + f.VerifyCurrentLineContent(t, ` break;`) + f.GoToMarker(t, "47") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "48") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "49") + f.VerifyCurrentLineContent(t, ` var a = { b: function() { } };`) + f.GoToMarker(t, "50") + f.VerifyCurrentLineContent(t, ` return { a: 1, b: 2 }`) + f.GoToMarker(t, "51") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "52") + f.VerifyCurrentLineContent(t, `var z = 1;`) + f.GoToMarker(t, "53") + f.VerifyCurrentLineContent(t, `for (i = 0; i < 10; i++)`) + f.GoToMarker(t, "54") + f.VerifyCurrentLineContent(t, ` for (j = 0; j < 10; j++)`) + f.GoToMarker(t, "55") + f.VerifyCurrentLineContent(t, ` for (k = 0; k < 10; ++k) {`) + f.GoToMarker(t, "56") + f.VerifyCurrentLineContent(t, ` z++;`) + f.GoToMarker(t, "57") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "58") + f.VerifyCurrentLineContent(t, `for (k = 0; k < 10; k += 2) {`) + f.GoToMarker(t, "59") + f.VerifyCurrentLineContent(t, ` z++;`) + f.GoToMarker(t, "60") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "61") + f.VerifyCurrentLineContent(t, `$(document).ready();`) + f.GoToMarker(t, "62") + f.VerifyCurrentLineContent(t, `function pageLoad() {`) + f.GoToMarker(t, "63") + f.VerifyCurrentLineContent(t, ` $('#TextBox1').unbind();`) + f.GoToMarker(t, "64") + f.VerifyCurrentLineContent(t, ` $('#TextBox1').datepicker();`) + f.GoToMarker(t, "65") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "66") + f.VerifyCurrentLineContent(t, `function pageLoad() {`) + f.GoToMarker(t, "67") + f.VerifyCurrentLineContent(t, ` var webclass = [`) + f.GoToMarker(t, "68") + f.VerifyCurrentLineContent(t, ` {`) + f.GoToMarker(t, "69") + f.VerifyCurrentLineContent(t, ` 'student':`) + f.GoToMarker(t, "70") + f.VerifyCurrentLineContent(t, ` { 'id': '1', 'name': 'Linda Jones', 'legacySkill': 'Access, VB 5.0' }`) + f.GoToMarker(t, "71") + f.VerifyCurrentLineContent(t, ` },`) + f.GoToMarker(t, "72") + f.VerifyCurrentLineContent(t, ` {`) + f.GoToMarker(t, "73") + f.VerifyCurrentLineContent(t, ` 'student':`) + f.GoToMarker(t, "74") + f.VerifyCurrentLineContent(t, ` { 'id': '2', 'name': 'Adam Davidson', 'legacySkill': 'Cobol,MainFrame' }`) + f.GoToMarker(t, "75") + f.VerifyCurrentLineContent(t, ` },`) + f.GoToMarker(t, "76") + f.VerifyCurrentLineContent(t, ` {`) + f.GoToMarker(t, "77") + f.VerifyCurrentLineContent(t, ` 'student':`) + f.GoToMarker(t, "78") + f.VerifyCurrentLineContent(t, ` { 'id': '3', 'name': 'Charles Boyer', 'legacySkill': 'HTML, XML' }`) + f.GoToMarker(t, "79") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "80") + f.VerifyCurrentLineContent(t, ` ];`) + f.GoToMarker(t, "81") + f.VerifyCurrentLineContent(t, ` $create(Sys.UI.DataView, { data: webclass }, null, null, $get('SList'));`) + f.GoToMarker(t, "82") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "83") + f.VerifyCurrentLineContent(t, `$(document).ready(function() {`) + f.GoToMarker(t, "84") + f.VerifyCurrentLineContent(t, ` alert('hello');`) + f.GoToMarker(t, "85") + f.VerifyCurrentLineContent(t, `});`) +} diff --git a/internal/fourslash/tests/gen/formattingOnModuleIndentation_test.go b/internal/fourslash/tests/gen/formattingOnModuleIndentation_test.go new file mode 100644 index 0000000000..ef61be887b --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnModuleIndentation_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnModuleIndentation(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` module Foo { + export module A . B . C { }/**/ + }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToBOF(t) + f.VerifyCurrentLineContent(t, `module Foo {`) + f.GoToMarker(t, "") + f.VerifyCurrentLineContent(t, ` export module A.B.C { }`) + f.GoToEOF(t) + f.VerifyCurrentLineContent(t, `}`) +} diff --git a/internal/fourslash/tests/gen/formattingOnNestedDoWhileByEnter_test.go b/internal/fourslash/tests/gen/formattingOnNestedDoWhileByEnter_test.go new file mode 100644 index 0000000000..042fdc56f2 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnNestedDoWhileByEnter_test.go @@ -0,0 +1,37 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnNestedDoWhileByEnter(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*2*/do{ +/*3*/do/*1*/{ +/*4*/do{ +/*5*/}while(a!==b) +/*6*/}while(a!==b) +/*7*/}while(a!==b)` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "\n") + f.VerifyCurrentLineContent(t, ` {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `do{`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` do`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `do{`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `}while(a!==b)`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, `}while(a!==b)`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, `}while(a!==b)`) +} diff --git a/internal/fourslash/tests/gen/formattingOnObjectLiteral_test.go b/internal/fourslash/tests/gen/formattingOnObjectLiteral_test.go new file mode 100644 index 0000000000..634b403a75 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnObjectLiteral_test.go @@ -0,0 +1,98 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnObjectLiteral(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = /*1*/{foo:/*2*/ 1, +bar: "tt",/*3*/ +boo: /*4*/1 + 5}/*5*/; + +var x2 = /*6*/{foo/*7*/: 1, +bar: /*8*/"tt",boo:1+5}/*9*/; + +function Foo() {/*10*/ +var typeICalc = {/*11*/ +clear: {/*12*/ +"()": [1, 2, 3]/*13*/ +}/*14*/ +}/*15*/ +}/*16*/ + +// Rule for object literal members for the "value" of the memebr to follow the indent/*17*/ +// of the member, i.e. the relative position of the value is maintained when the member/*18*/ +// is indented./*19*/ +var x2 = {/*20*/ + foo:/*21*/ +3,/*22*/ + 'bar':/*23*/ + { a: 1, b : 2}/*24*/ +};/*25*/ + +var x={ };/*26*/ +var y = {};/*27*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `var x = {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` foo: 1,`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` bar: "tt",`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` boo: 1 + 5`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `};`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, `var x2 = {`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` foo: 1,`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, ` bar: "tt", boo: 1 + 5`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, `};`) + f.GoToMarker(t, "10") + f.VerifyCurrentLineContent(t, `function Foo() {`) + f.GoToMarker(t, "11") + f.VerifyCurrentLineContent(t, ` var typeICalc = {`) + f.GoToMarker(t, "12") + f.VerifyCurrentLineContent(t, ` clear: {`) + f.GoToMarker(t, "13") + f.VerifyCurrentLineContent(t, ` "()": [1, 2, 3]`) + f.GoToMarker(t, "14") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "15") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "16") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "17") + f.VerifyCurrentLineContent(t, `// Rule for object literal members for the "value" of the memebr to follow the indent`) + f.GoToMarker(t, "18") + f.VerifyCurrentLineContent(t, `// of the member, i.e. the relative position of the value is maintained when the member`) + f.GoToMarker(t, "19") + f.VerifyCurrentLineContent(t, `// is indented.`) + f.GoToMarker(t, "20") + f.VerifyCurrentLineContent(t, `var x2 = {`) + f.GoToMarker(t, "21") + f.VerifyCurrentLineContent(t, ` foo:`) + f.GoToMarker(t, "22") + f.VerifyCurrentLineContent(t, ` 3,`) + f.GoToMarker(t, "23") + f.VerifyCurrentLineContent(t, ` 'bar':`) + f.GoToMarker(t, "24") + f.VerifyCurrentLineContent(t, ` { a: 1, b: 2 }`) + f.GoToMarker(t, "25") + f.VerifyCurrentLineContent(t, `};`) + f.GoToMarker(t, "26") + f.VerifyCurrentLineContent(t, `var x = {};`) + f.GoToMarker(t, "27") + f.VerifyCurrentLineContent(t, `var y = {};`) +} diff --git a/internal/fourslash/tests/gen/formattingOnOpenBraceOfFunctions_test.go b/internal/fourslash/tests/gen/formattingOnOpenBraceOfFunctions_test.go new file mode 100644 index 0000000000..64e229edb7 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnOpenBraceOfFunctions_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnOpenBraceOfFunctions(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/function T2_y() +{ +Plugin.T1.t1_x(); +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "") + f.VerifyCurrentLineContent(t, `function T2_y() {`) +} diff --git a/internal/fourslash/tests/gen/formattingOnSemiColon_test.go b/internal/fourslash/tests/gen/formattingOnSemiColon_test.go new file mode 100644 index 0000000000..c83eaa0dac --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnSemiColon_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnSemiColon(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var a=b+c^d-e*++f` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToEOF(t) + f.Insert(t, ";") + f.VerifyCurrentFileContent(t, `var a = b + c ^ d - e * ++f;`) +} diff --git a/internal/fourslash/tests/gen/formattingOnSingleLineBlocks_test.go b/internal/fourslash/tests/gen/formattingOnSingleLineBlocks_test.go new file mode 100644 index 0000000000..ab9204751e --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnSingleLineBlocks_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnSingleLineBlocks(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C +{} +if (true) +{}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `class C { } +if (true) { }`) +} diff --git a/internal/fourslash/tests/gen/formattingOnStatementsWithNoSemicolon_test.go b/internal/fourslash/tests/gen/formattingOnStatementsWithNoSemicolon_test.go new file mode 100644 index 0000000000..c6f2a0adec --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnStatementsWithNoSemicolon_test.go @@ -0,0 +1,184 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnStatementsWithNoSemicolon(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/do + { var a/*2*/ +/*3*/} while (1) +/*4*/function f() { +/*5*/ var s = 1 +/*6*/ } +/*7*/switch (t) { +/*8*/ case 1: +/*9*/{ +/*10*/test +/*11*/} +/*12*/} +/*13*/do{do{do{}while(a!==b)}while(a!==b)}while(a!==b) +/*14*/do{ +/*15*/do{ +/*16*/do{ +/*17*/}while(a!==b) +/*18*/}while(a!==b) +/*19*/}while(a!==b) +/*20*/for(var i=0;i<10;i++){ +/*21*/for(var j=0;j<10;j++){ +/*22*/j-=i +/*23*/}/*24*/} +/*25*/function foo() { +/*26*/try { +/*27*/x+=2 +/*28*/} +/*29*/catch( e){ +/*30*/x+=2 +/*31*/}finally { +/*32*/x+=2 +/*33*/} +/*34*/} +/*35*/do { var a } while (1) + foo(function (file) {/*49*/ + return 0/*50*/ + }).then(function (doc) {/*51*/ + return 1/*52*/ + });/*53*/ +/*54*/if(1) +/*55*/if(1) +/*56*/x++ +/*57*/else +/*58*/if(1) +/*59*/x+=2 +/*60*/else +/*61*/x+=2 + + + +/*62*/; + do do do do/*63*/ + test;/*64*/ + while (0)/*65*/ + while (0)/*66*/ + while (0)/*67*/ + while (0)/*68*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `do {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` var a`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `} while (1)`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `function f() {`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` var s = 1`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, `switch (t) {`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, ` case 1:`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, ` {`) + f.GoToMarker(t, "10") + f.VerifyCurrentLineContent(t, ` test`) + f.GoToMarker(t, "11") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "12") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "13") + f.VerifyCurrentLineContent(t, `do { do { do { } while (a !== b) } while (a !== b) } while (a !== b)`) + f.GoToMarker(t, "14") + f.VerifyCurrentLineContent(t, `do {`) + f.GoToMarker(t, "15") + f.VerifyCurrentLineContent(t, ` do {`) + f.GoToMarker(t, "16") + f.VerifyCurrentLineContent(t, ` do {`) + f.GoToMarker(t, "17") + f.VerifyCurrentLineContent(t, ` } while (a !== b)`) + f.GoToMarker(t, "18") + f.VerifyCurrentLineContent(t, ` } while (a !== b)`) + f.GoToMarker(t, "19") + f.VerifyCurrentLineContent(t, `} while (a !== b)`) + f.GoToMarker(t, "20") + f.VerifyCurrentLineContent(t, `for (var i = 0; i < 10; i++) {`) + f.GoToMarker(t, "21") + f.VerifyCurrentLineContent(t, ` for (var j = 0; j < 10; j++) {`) + f.GoToMarker(t, "22") + f.VerifyCurrentLineContent(t, ` j -= i`) + f.GoToMarker(t, "23") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "24") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "25") + f.VerifyCurrentLineContent(t, `function foo() {`) + f.GoToMarker(t, "26") + f.VerifyCurrentLineContent(t, ` try {`) + f.GoToMarker(t, "27") + f.VerifyCurrentLineContent(t, ` x += 2`) + f.GoToMarker(t, "28") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "29") + f.VerifyCurrentLineContent(t, ` catch (e) {`) + f.GoToMarker(t, "30") + f.VerifyCurrentLineContent(t, ` x += 2`) + f.GoToMarker(t, "31") + f.VerifyCurrentLineContent(t, ` } finally {`) + f.GoToMarker(t, "32") + f.VerifyCurrentLineContent(t, ` x += 2`) + f.GoToMarker(t, "33") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "34") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "35") + f.VerifyCurrentLineContent(t, `do { var a } while (1)`) + f.GoToMarker(t, "49") + f.VerifyCurrentLineContent(t, `foo(function(file) {`) + f.GoToMarker(t, "50") + f.VerifyCurrentLineContent(t, ` return 0`) + f.GoToMarker(t, "51") + f.VerifyCurrentLineContent(t, `}).then(function(doc) {`) + f.GoToMarker(t, "52") + f.VerifyCurrentLineContent(t, ` return 1`) + f.GoToMarker(t, "53") + f.VerifyCurrentLineContent(t, `});`) + f.GoToMarker(t, "54") + f.VerifyCurrentLineContent(t, `if (1)`) + f.GoToMarker(t, "55") + f.VerifyCurrentLineContent(t, ` if (1)`) + f.GoToMarker(t, "56") + f.VerifyCurrentLineContent(t, ` x++`) + f.GoToMarker(t, "57") + f.VerifyCurrentLineContent(t, ` else`) + f.GoToMarker(t, "58") + f.VerifyCurrentLineContent(t, ` if (1)`) + f.GoToMarker(t, "59") + f.VerifyCurrentLineContent(t, ` x += 2`) + f.GoToMarker(t, "60") + f.VerifyCurrentLineContent(t, ` else`) + f.GoToMarker(t, "61") + f.VerifyCurrentLineContent(t, ` x += 2`) + f.GoToMarker(t, "62") + f.VerifyCurrentLineContent(t, ` ;`) + f.GoToMarker(t, "63") + f.VerifyCurrentLineContent(t, `do do do do`) + f.GoToMarker(t, "64") + f.VerifyCurrentLineContent(t, ` test;`) + f.GoToMarker(t, "65") + f.VerifyCurrentLineContent(t, `while (0)`) + f.GoToMarker(t, "66") + f.VerifyCurrentLineContent(t, `while (0)`) + f.GoToMarker(t, "67") + f.VerifyCurrentLineContent(t, `while (0)`) + f.GoToMarker(t, "68") + f.VerifyCurrentLineContent(t, `while (0)`) +} diff --git a/internal/fourslash/tests/gen/formattingOnTabAfterCloseCurly_test.go b/internal/fourslash/tests/gen/formattingOnTabAfterCloseCurly_test.go new file mode 100644 index 0000000000..4d77cbf659 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnTabAfterCloseCurly_test.go @@ -0,0 +1,45 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnTabAfterCloseCurly(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module Tools {/*1*/ + export enum NodeType {/*2*/ + Error,/*3*/ + Comment,/*4*/ + } /*5*/ + export enum foob/*6*/ + { + Blah=1, Bleah=2/*7*/ + }/*8*/ +}/*9*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `module Tools {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` export enum NodeType {`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` Error,`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` Comment,`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` export enum foob {`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` Blah = 1, Bleah = 2`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, `}`) +} diff --git a/internal/fourslash/tests/gen/formattingOnVariety_test.go b/internal/fourslash/tests/gen/formattingOnVariety_test.go new file mode 100644 index 0000000000..d6839f509e --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnVariety_test.go @@ -0,0 +1,66 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnVariety(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function f(a,b,c,d){/*1*/ +for(var i=0;i<10;i++){/*2*/ +var a=0;/*3*/ +var b=a+a+a*a%a/2-1;/*4*/ +b+=a;/*5*/ +++b;/*6*/ +f(a,b,c,d);/*7*/ +if(1===1){/*8*/ +var m=function(e,f){/*9*/ +return e^f;/*10*/ +}/*11*/ +}/*12*/ +}/*13*/ +}/*14*/ + +for (var i = 0 ; i < this.foo(); i++) {/*15*/ +}/*16*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `function f(a, b, c, d) {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` for (var i = 0; i < 10; i++) {`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` var a = 0;`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` var b = a + a + a * a % a / 2 - 1;`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` b += a;`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` ++b;`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` f(a, b, c, d);`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, ` if (1 === 1) {`) + f.GoToMarker(t, "9") + f.VerifyCurrentLineContent(t, ` var m = function(e, f) {`) + f.GoToMarker(t, "10") + f.VerifyCurrentLineContent(t, ` return e ^ f;`) + f.GoToMarker(t, "11") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "12") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "13") + f.VerifyCurrentLineContent(t, ` }`) + f.GoToMarker(t, "14") + f.VerifyCurrentLineContent(t, `}`) + f.GoToMarker(t, "15") + f.VerifyCurrentLineContent(t, `for (var i = 0; i < this.foo(); i++) {`) + f.GoToMarker(t, "16") + f.VerifyCurrentLineContent(t, `}`) +} diff --git a/internal/fourslash/tests/gen/formattingQMark_test.go b/internal/fourslash/tests/gen/formattingQMark_test.go new file mode 100644 index 0000000000..8d05c27612 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingQMark_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingQMark(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface A { +/*1*/ foo? (); +/*2*/ foo? (); +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` foo?();`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` foo?();`) +} diff --git a/internal/fourslash/tests/gen/formattingReadonly_test.go b/internal/fourslash/tests/gen/formattingReadonly_test.go new file mode 100644 index 0000000000..011cb7a526 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingReadonly_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingReadonly(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + readonly property1: {};/*1*/ + public readonly property2: {};/*2*/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` readonly property1: {};`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` public readonly property2: {};`) +} diff --git a/internal/fourslash/tests/gen/formattingRegexes_test.go b/internal/fourslash/tests/gen/formattingRegexes_test.go new file mode 100644 index 0000000000..04babb351b --- /dev/null +++ b/internal/fourslash/tests/gen/formattingRegexes_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingRegexes(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `removeAllButLast(sortedTypes, undefinedType, /keepNullableType**/ true)/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, `removeAllButLast(sortedTypes, undefinedType, /keepNullableType**/ true);`) +} diff --git a/internal/fourslash/tests/gen/formattingReplaceTabsWithSpaces_test.go b/internal/fourslash/tests/gen/formattingReplaceTabsWithSpaces_test.go new file mode 100644 index 0000000000..9f82468ebe --- /dev/null +++ b/internal/fourslash/tests/gen/formattingReplaceTabsWithSpaces_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingReplaceTabsWithSpaces(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module Foo { +/*1*/ class Test { } +/*2*/ class Test { } +/*3*/class Test { } +/*4*/ class Test { } +/*5*/ class Test { } +/*6*/ class Test { } +/*7*/ class Test { } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` class Test { }`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` class Test { }`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` class Test { }`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` class Test { }`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` class Test { }`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` class Test { }`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` class Test { }`) +} diff --git a/internal/fourslash/tests/gen/formattingSingleLineWithNewLineOptionSet_test.go b/internal/fourslash/tests/gen/formattingSingleLineWithNewLineOptionSet_test.go new file mode 100644 index 0000000000..34a963b76f --- /dev/null +++ b/internal/fourslash/tests/gen/formattingSingleLineWithNewLineOptionSet_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingSingleLineWithNewLineOptionSet(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/module Default{} +/*2*/function foo(){} +/*3*/if (true){} +/*4*/function boo() { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "PlaceOpenBraceOnNewLineForFunctions", true) + f.SetFormatOption(t, "PlaceOpenBraceOnNewLineForControlBlocks", true) + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `module Default { }`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `function foo() { }`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `if (true) { }`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `function boo()`) +} diff --git a/internal/fourslash/tests/gen/formattingSkippedTokens_test.go b/internal/fourslash/tests/gen/formattingSkippedTokens_test.go new file mode 100644 index 0000000000..d52b631fd7 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingSkippedTokens_test.go @@ -0,0 +1,35 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingSkippedTokens(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/foo(): Bar { } +/*2*/function Foo () # { } +/*3*/4+:5 + module M { +function a( +/*4*/ : T) { } +} +/*5*/var x =` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `foo(): Bar { }`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `function Foo() # { }`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `4 +: 5`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, ` : T) { }`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `var x =`) +} diff --git a/internal/fourslash/tests/gen/formattingSpaceAfterCommaBeforeOpenParen_test.go b/internal/fourslash/tests/gen/formattingSpaceAfterCommaBeforeOpenParen_test.go new file mode 100644 index 0000000000..2c9cff6125 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingSpaceAfterCommaBeforeOpenParen_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingSpaceAfterCommaBeforeOpenParen(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `foo(a,(b))/*1*/ +foo(a,(c).d)/*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, `foo(a, (b));`) + f.GoToMarker(t, "2") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, `foo(a, (c).d);`) +} diff --git a/internal/fourslash/tests/gen/formattingSpaceBeforeCloseParen_test.go b/internal/fourslash/tests/gen/formattingSpaceBeforeCloseParen_test.go new file mode 100644 index 0000000000..81db202f08 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingSpaceBeforeCloseParen_test.go @@ -0,0 +1,45 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingSpaceBeforeCloseParen(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/({}); +/*2*/( {}); +/*3*/({foo:42}); +/*4*/( {foo:42} ); +/*5*/var bar = (function (a) { });` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis", true) + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `( {} );`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `( {} );`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `( { foo: 42 } );`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `( { foo: 42 } );`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `var bar = ( function( a ) { } );`) + f.SetFormatOption(t, "InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis", false) + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `({});`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `({});`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `({ foo: 42 });`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `({ foo: 42 });`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `var bar = (function(a) { });`) +} diff --git a/internal/fourslash/tests/gen/formattingSpaceBeforeFunctionParen_test.go b/internal/fourslash/tests/gen/formattingSpaceBeforeFunctionParen_test.go new file mode 100644 index 0000000000..d0c63bb7cc --- /dev/null +++ b/internal/fourslash/tests/gen/formattingSpaceBeforeFunctionParen_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingSpaceBeforeFunctionParen(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/function foo() { } +/*2*/function boo () { } +/*3*/var bar = function foo() { }; +/*4*/var foo = { bar() { } }; +/*5*/function tmpl () { } +/*6*/var f = function*() { }; +/*7*/function* g () { }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "insertSpaceBeforeFunctionParenthesis", true) + f.SetFormatOption(t, "insertSpaceAfterFunctionKeywordForAnonymousFunctions", false) + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `function foo () { }`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `function boo () { }`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `var bar = function foo () { };`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `var foo = { bar () { } };`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `function tmpl () { }`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, `var f = function*() { };`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, `function* g () { }`) +} diff --git a/internal/fourslash/tests/gen/formattingSpaceBetweenOptionalChaining_test.go b/internal/fourslash/tests/gen/formattingSpaceBetweenOptionalChaining_test.go new file mode 100644 index 0000000000..8b0f840838 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingSpaceBetweenOptionalChaining_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingSpaceBetweenOptionalChaining(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/a ?. b ?. c . d; +/*2*/o . m() ?. length;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `a?.b?.c.d;`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `o.m()?.length;`) +} diff --git a/internal/fourslash/tests/gen/formattingSpaceBetweenParent_test.go b/internal/fourslash/tests/gen/formattingSpaceBetweenParent_test.go new file mode 100644 index 0000000000..fb976a91fb --- /dev/null +++ b/internal/fourslash/tests/gen/formattingSpaceBetweenParent_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingSpaceBetweenParent(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/foo(() => 1); +/*2*/foo(1); +/*3*/if((true)){}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.SetFormatOption(t, "InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis", true) + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `foo( () => 1 );`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `foo( 1 );`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `if ( ( true ) ) { }`) +} diff --git a/internal/fourslash/tests/gen/formattingSpacesAfterConstructor_test.go b/internal/fourslash/tests/gen/formattingSpacesAfterConstructor_test.go new file mode 100644 index 0000000000..51bed0b752 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingSpacesAfterConstructor_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingSpacesAfterConstructor(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/class test { constructor () { } } +/*2*/class test { constructor () { } }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `class test { constructor() { } }`) + f.SetFormatOption(t, "InsertSpaceAfterConstructor", true) + f.FormatDocument(t, "") + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `class test { constructor () { } }`) +} diff --git a/internal/fourslash/tests/gen/formattingTemplatesWithNewline_test.go b/internal/fourslash/tests/gen/formattingTemplatesWithNewline_test.go new file mode 100644 index 0000000000..32aeabd1a0 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingTemplatesWithNewline_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingTemplatesWithNewline(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `` + "`" + `${1}` + "`" + `; +` + "`" + ` +` + "`" + `;/**/1` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "\n") + f.VerifyCurrentLineContent(t, `1`) +} diff --git a/internal/fourslash/tests/gen/formattingTemplates_test.go b/internal/fourslash/tests/gen/formattingTemplates_test.go new file mode 100644 index 0000000000..d9ec38116f --- /dev/null +++ b/internal/fourslash/tests/gen/formattingTemplates_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingTemplates(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `String.call ` + "`" + `${123}` + "`" + `/*1*/ +String.call ` + "`" + `${123} ${456}` + "`" + `/*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, "String.call`${123}`;") + f.GoToMarker(t, "2") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, "String.call`${123} ${456}`;") +} diff --git a/internal/fourslash/tests/gen/formattingTypeInfer_test.go b/internal/fourslash/tests/gen/formattingTypeInfer_test.go new file mode 100644 index 0000000000..0445db6a7d --- /dev/null +++ b/internal/fourslash/tests/gen/formattingTypeInfer_test.go @@ -0,0 +1,50 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingTypeInfer(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +/*L1*/type C = T extends Array ? U : never; + +/*L2*/ type C < T > = T extends Array < infer U > ? U : never ; + +/*L3*/type C = T extends Array ? U : T; + +/*L4*/ type C < T > = T extends Array < infer U > ? U : T ; + +/*L5*/type Foo = T extends { a: infer U, b: infer U } ? U : never; + +/*L6*/ type Foo < T > = T extends { a : infer U , b : infer U } ? U : never ; + +/*L7*/type Bar = T extends { a: (x: infer U) => void, b: (x: infer U) => void } ? U : never; + +/*L8*/ type Bar < T > = T extends { a : (x : infer U ) => void , b : (x : infer U ) => void } ? U : never ; +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "L1") + f.VerifyCurrentLineContent(t, `type C = T extends Array ? U : never;`) + f.GoToMarker(t, "L2") + f.VerifyCurrentLineContent(t, `type C = T extends Array ? U : never;`) + f.GoToMarker(t, "L3") + f.VerifyCurrentLineContent(t, `type C = T extends Array ? U : T;`) + f.GoToMarker(t, "L4") + f.VerifyCurrentLineContent(t, `type C = T extends Array ? U : T;`) + f.GoToMarker(t, "L5") + f.VerifyCurrentLineContent(t, `type Foo = T extends { a: infer U, b: infer U } ? U : never;`) + f.GoToMarker(t, "L6") + f.VerifyCurrentLineContent(t, `type Foo = T extends { a: infer U, b: infer U } ? U : never;`) + f.GoToMarker(t, "L7") + f.VerifyCurrentLineContent(t, `type Bar = T extends { a: (x: infer U) => void, b: (x: infer U) => void } ? U : never;`) + f.GoToMarker(t, "L8") + f.VerifyCurrentLineContent(t, `type Bar = T extends { a: (x: infer U) => void, b: (x: infer U) => void } ? U : never;`) +} diff --git a/internal/fourslash/tests/gen/formattingVoid_test.go b/internal/fourslash/tests/gen/formattingVoid_test.go new file mode 100644 index 0000000000..47ab7da32c --- /dev/null +++ b/internal/fourslash/tests/gen/formattingVoid_test.go @@ -0,0 +1,36 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingVoid(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/ var x: () => void ; +/*2*/ var y: void ; +/*3*/ function test(a:void,b:string){} +/*4*/ var a, b, c, d; +/*5*/ void a ; +/*6*/ void (0); +/*7*/ b=void(c=1,d=2);` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `var x: () => void;`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `var y: void;`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `function test(a: void, b: string) { }`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `void a;`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, `void (0);`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, `b = void (c = 1, d = 2);`) +} diff --git a/internal/fourslash/tests/gen/formattingWithMultilineComments_test.go b/internal/fourslash/tests/gen/formattingWithMultilineComments_test.go new file mode 100644 index 0000000000..8b4e6c36e4 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingWithMultilineComments_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingWithMultilineComments(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `f(/* +/*2*/ */() => { /*1*/ });` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.InsertLine(t, "") + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` */() => {`) +} diff --git a/internal/fourslash/tests/gen/formattingofSingleLineBlockConstructs_test.go b/internal/fourslash/tests/gen/formattingofSingleLineBlockConstructs_test.go new file mode 100644 index 0000000000..b311156df0 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingofSingleLineBlockConstructs_test.go @@ -0,0 +1,53 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingofSingleLineBlockConstructs(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module InternalModule/*1*/{} +interface MyInterface/*2*/{} +enum E/*3*/{} +class MyClass/*4*/{ +constructor()/*cons*/{} + public MyFunction()/*5*/{return 0;} +public get Getter()/*6*/{} +public set Setter(x)/*7*/{}} +function foo()/*8*/{{}} +(function()/*10*/{}); +(() =>/*11*/{}); +var x :/*12*/{};` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `module InternalModule { }`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `interface MyInterface { }`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `enum E { }`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `class MyClass {`) + f.GoToMarker(t, "cons") + f.VerifyCurrentLineContent(t, ` constructor() { }`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, ` public MyFunction() { return 0; }`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, ` public get Getter() { }`) + f.GoToMarker(t, "7") + f.VerifyCurrentLineContent(t, ` public set Setter(x) { }`) + f.GoToMarker(t, "8") + f.VerifyCurrentLineContent(t, `function foo() { { } }`) + f.GoToMarker(t, "10") + f.VerifyCurrentLineContent(t, `(function() { });`) + f.GoToMarker(t, "11") + f.VerifyCurrentLineContent(t, `(() => { });`) + f.GoToMarker(t, "12") + f.VerifyCurrentLineContent(t, `var x: {};`) +} diff --git a/internal/fourslash/tests/gen/functionFormatting_test.go b/internal/fourslash/tests/gen/functionFormatting_test.go new file mode 100644 index 0000000000..d255bdfb5c --- /dev/null +++ b/internal/fourslash/tests/gen/functionFormatting_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFunctionFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var foo = foo(function () { + /**/function foo () {}} );` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "") + f.VerifyCurrentLineContent(t, ` function foo() { }`) +} diff --git a/internal/fourslash/tests/gen/functionIndentation_test.go b/internal/fourslash/tests/gen/functionIndentation_test.go new file mode 100644 index 0000000000..0ac5c55005 --- /dev/null +++ b/internal/fourslash/tests/gen/functionIndentation_test.go @@ -0,0 +1,93 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFunctionIndentation(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M { +export = +C; +class C { +constructor(b +) { +} +foo(a +: string) { +return a +|| true; +} +get bar( +) { +return 1; +} +} +function foo(a, +b?) { +new M.C( +"hello"); +} +{ +{ +} +} +foo( +function() { +"hello"; +}); +foo( +() => { +"hello"; +}); +var t, +u = 1, +v; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `module M { +`+` export = +`+` C; +`+` class C { +`+` constructor(b +`+` ) { +`+` } +`+` foo(a +`+` : string) { +`+` return a +`+` || true; +`+` } +`+` get bar( +`+` ) { +`+` return 1; +`+` } +`+` } +`+` function foo(a, +`+` b?) { +`+` new M.C( +`+` "hello"); +`+` } +`+` { +`+` { +`+` } +`+` } +`+` foo( +`+` function() { +`+` "hello"; +`+` }); +`+` foo( +`+` () => { +`+` "hello"; +`+` }); +`+` var t, +`+` u = 1, +`+` v; +`+`}`) +} diff --git a/internal/fourslash/tests/gen/functionTypeFormatting_test.go b/internal/fourslash/tests/gen/functionTypeFormatting_test.go new file mode 100644 index 0000000000..d7fc60fada --- /dev/null +++ b/internal/fourslash/tests/gen/functionTypeFormatting_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFunctionTypeFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x: () => string/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, `var x: () => string;`) +} diff --git a/internal/fourslash/tests/gen/functionTypePredicateFormatting_test.go b/internal/fourslash/tests/gen/functionTypePredicateFormatting_test.go new file mode 100644 index 0000000000..e62aa4efc6 --- /dev/null +++ b/internal/fourslash/tests/gen/functionTypePredicateFormatting_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFunctionTypePredicateFormatting(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/function bar(a: A): a is B {}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.FormatDocument(t, "") + f.VerifyCurrentLineContent(t, `function bar(a: A): a is B { }`) +} diff --git a/internal/fourslash/tests/gen/generatorDeclarationFormatting_test.go b/internal/fourslash/tests/gen/generatorDeclarationFormatting_test.go new file mode 100644 index 0000000000..d68e1f1624 --- /dev/null +++ b/internal/fourslash/tests/gen/generatorDeclarationFormatting_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGeneratorDeclarationFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function *g() { }/*1*/ +var v = function *() { };/*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `function* g() { }`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `var v = function*() { };`) +} diff --git a/internal/fourslash/tests/gen/genericsFormattingMultiline_test.go b/internal/fourslash/tests/gen/genericsFormattingMultiline_test.go new file mode 100644 index 0000000000..81e68b51d6 --- /dev/null +++ b/internal/fourslash/tests/gen/genericsFormattingMultiline_test.go @@ -0,0 +1,85 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericsFormattingMultiline(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +class Foo < + T1 extends unknown, + T2 + > { + public method < + T3, + > (a: T1, b: Array < + string + > ): Map < + T1 , + Array < T3 > + > { throw new Error(); } +} + +interface IFoo< + T, + > { + new < T + > ( a: T); + op?< + T, + M + > (a: T, b : M ); + < + T, + >(x: T): T; +} + +type foo< + T + > = Foo < + number, Array < number > > ; + +function bar < +T, U extends T + > () { + return class < + T2, + > { + } +} + +bar< +string, + "s" + > (); + +declare const func: < +T extends number[], + > (x: T) => new < + U + > () => U; + +class A < T > extends bar < + T,number + >( ) < T + > { +} + +function s(x: TemplateStringsArray, ...args: any[]) { return x.join(); } + +const t = s< + number , + string[] & ArrayLike + >` + "`" + `abc${1}def` + "`" + ` ; +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, "\nclass Foo<\n T1 extends unknown,\n T2\n> {\n public method<\n T3,\n >(a: T1, b: Array<\n string\n >): Map<\n T1,\n Array\n > { throw new Error(); }\n}\n\ninterface IFoo<\n T,\n> {\n new (a: T);\n op?<\n T,\n M\n >(a: T, b: M);\n <\n T,\n >(x: T): T;\n}\n\ntype foo<\n T\n> = Foo<\n number, Array>;\n\nfunction bar<\n T, U extends T\n>() {\n return class <\n T2,\n > {\n }\n}\n\nbar<\n string,\n \"s\"\n>();\n\ndeclare const func: <\n T extends number[],\n> (x: T) => new <\n U\n> () => U;\n\nclass A extends bar<\n T, number\n>() {\n}\n\nfunction s(x: TemplateStringsArray, ...args: any[]) { return x.join(); }\n\nconst t = s<\n number,\n string[] & ArrayLike\n>`abc${1}def`;\n") +} diff --git a/internal/fourslash/tests/gen/genericsFormatting_test.go b/internal/fourslash/tests/gen/genericsFormatting_test.go new file mode 100644 index 0000000000..eec56672ac --- /dev/null +++ b/internal/fourslash/tests/gen/genericsFormatting_test.go @@ -0,0 +1,56 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericsFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*inClassDeclaration*/class Foo < T1 , T2 > { +/*inMethodDeclaration*/ public method < T3, T4 > ( a: T1, b: Array < T4 > ): Map < T1 , T2, Array < T3 > > { + } +} +/*typeArguments*/var foo = new Foo < number, Array < number > > ( ); +/*typeArgumentsWithTypeLiterals*/foo = new Foo < { bar : number }, Array < { baz : string } > > ( ); + +interface IFoo { +/*inNewSignature*/new < T > ( a: T); +/*inOptionalMethodSignature*/op?< T , M > (a: T, b : M ); +} + +foo()(); +(a + b)(); + +/*inFunctionDeclaration*/function bar () { +/*inClassExpression*/ return class < T2 > { + } +} +/*expressionWithTypeArguments*/class A < T > extends bar < T >( ) < T > { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "inClassDeclaration") + f.VerifyCurrentLineContent(t, `class Foo {`) + f.GoToMarker(t, "inMethodDeclaration") + f.VerifyCurrentLineContent(t, ` public method(a: T1, b: Array): Map> {`) + f.GoToMarker(t, "typeArguments") + f.VerifyCurrentLineContent(t, `var foo = new Foo>();`) + f.GoToMarker(t, "typeArgumentsWithTypeLiterals") + f.VerifyCurrentLineContent(t, `foo = new Foo<{ bar: number }, Array<{ baz: string }>>();`) + f.GoToMarker(t, "inNewSignature") + f.VerifyCurrentLineContent(t, ` new (a: T);`) + f.GoToMarker(t, "inOptionalMethodSignature") + f.VerifyCurrentLineContent(t, ` op?(a: T, b: M);`) + f.GoToMarker(t, "inFunctionDeclaration") + f.VerifyCurrentLineContent(t, `function bar() {`) + f.GoToMarker(t, "inClassExpression") + f.VerifyCurrentLineContent(t, ` return class {`) + f.GoToMarker(t, "expressionWithTypeArguments") + f.VerifyCurrentLineContent(t, `class A extends bar() {`) +} diff --git a/internal/fourslash/tests/gen/importNameCodeFix_externalNonRelateive2_test.go b/internal/fourslash/tests/gen/importNameCodeFix_externalNonRelateive2_test.go new file mode 100644 index 0000000000..5c35fee0c2 --- /dev/null +++ b/internal/fourslash/tests/gen/importNameCodeFix_externalNonRelateive2_test.go @@ -0,0 +1,56 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestImportNameCodeFix_externalNonRelateive2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/apps/app1/tsconfig.json +{ + "compilerOptions": { + "module": "commonjs", + "paths": { + "shared/*": ["../../shared/*"] + } + }, + "include": ["src", "../../shared"] +} +// @Filename: /home/src/workspaces/project/apps/app1/src/index.ts +shared/*internal2external*/ +// @Filename: /home/src/workspaces/project/apps/app1/src/app.ts +utils/*internal2internal*/ +// @Filename: /home/src/workspaces/project/apps/app1/src/utils.ts +export const utils = 0; +// @Filename: /home/src/workspaces/project/shared/constants.ts +export const shared = 0; +// @Filename: /home/src/workspaces/project/shared/data.ts +shared/*external2external*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.SetFormatOption(t, "newline", "\n") + f.GoToMarker(t, "internal2external") + f.VerifyImportFixAtPosition(t, []string{ + `import { shared } from "shared/constants"; + +shared`, + }, nil /*preferences*/) + f.GoToMarker(t, "internal2internal") + f.VerifyImportFixAtPosition(t, []string{ + `import { utils } from "./utils"; + +utils`, + }, nil /*preferences*/) + f.GoToMarker(t, "external2external") + f.VerifyImportFixAtPosition(t, []string{ + `import { shared } from "./constants"; + +shared`, + }, nil /*preferences*/) +} diff --git a/internal/fourslash/tests/gen/importNameCodeFix_externalNonRelative1_test.go b/internal/fourslash/tests/gen/importNameCodeFix_externalNonRelative1_test.go new file mode 100644 index 0000000000..4be6c56893 --- /dev/null +++ b/internal/fourslash/tests/gen/importNameCodeFix_externalNonRelative1_test.go @@ -0,0 +1,65 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestImportNameCodeFix_externalNonRelative1(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/tsconfig.base.json +{ + "compilerOptions": { + "module": "commonjs", + "paths": { + "pkg-1/*": ["./packages/pkg-1/src/*"], + "pkg-2/*": ["./packages/pkg-2/src/*"] + } + } +} +// @Filename: /home/src/workspaces/project/packages/pkg-1/package.json +{ "dependencies": { "pkg-2": "*" } } +// @Filename: /home/src/workspaces/project/packages/pkg-1/tsconfig.json +{ + "extends": "../../tsconfig.base.json", + "references": [ + { "path": "../pkg-2" } + ] +} +// @Filename: /home/src/workspaces/project/packages/pkg-1/src/index.ts +Pkg2/*external*/ +// @Filename: /home/src/workspaces/project/packages/pkg-2/package.json +{ "types": "dist/index.d.ts" } +// @Filename: /home/src/workspaces/project/packages/pkg-2/tsconfig.json +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { "outDir": "dist", "rootDir": "src", "composite": true } +} +// @Filename: /home/src/workspaces/project/packages/pkg-2/src/index.ts +import "./utils"; +// @Filename: /home/src/workspaces/project/packages/pkg-2/src/utils.ts +export const Pkg2 = {}; +// @Filename: /home/src/workspaces/project/packages/pkg-2/src/blah/foo/data.ts +Pkg2/*internal*/ +// @link: /home/src/workspaces/project/packages/pkg-2 -> /home/src/workspaces/project/packages/pkg-1/node_modules/pkg-2` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.SetFormatOption(t, "newline", "\n") + f.GoToMarker(t, "external") + f.VerifyImportFixAtPosition(t, []string{ + `import { Pkg2 } from "pkg-2/utils"; + +Pkg2`, + }, nil /*preferences*/) + f.GoToMarker(t, "internal") + f.VerifyImportFixAtPosition(t, []string{ + `import { Pkg2 } from "../../utils"; + +Pkg2`, + }, nil /*preferences*/) +} diff --git a/internal/fourslash/tests/gen/importTypeFormatting_test.go b/internal/fourslash/tests/gen/importTypeFormatting_test.go new file mode 100644 index 0000000000..992f61d8a5 --- /dev/null +++ b/internal/fourslash/tests/gen/importTypeFormatting_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestImportTypeFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var y: import("./c2").mytype; +var z: import ("./c2").mytype;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `var y: import("./c2").mytype; +var z: import("./c2").mytype;`) +} diff --git a/internal/fourslash/tests/gen/indentAfterFunctionClosingBraces_test.go b/internal/fourslash/tests/gen/indentAfterFunctionClosingBraces_test.go new file mode 100644 index 0000000000..17220b6376 --- /dev/null +++ b/internal/fourslash/tests/gen/indentAfterFunctionClosingBraces_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIndentAfterFunctionClosingBraces(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class foo { + public f() { + return 0; + /*1*/}/*2*/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "2") + f.InsertLine(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` }`) +} diff --git a/internal/fourslash/tests/gen/indentationInJsx3_test.go b/internal/fourslash/tests/gen/indentationInJsx3_test.go new file mode 100644 index 0000000000..5c0efe00e5 --- /dev/null +++ b/internal/fourslash/tests/gen/indentationInJsx3_test.go @@ -0,0 +1,42 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIndentationInJsx3(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `//@Filename: file.tsx +function foo() { + return ( +
+hello +goodbye +
+ ) +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyCurrentFileContent(t, `function foo() { + return ( +
+hello +goodbye +
+ ) +}`) + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `function foo() { + return ( +
+ hello + goodbye +
+ ) +}`) +} diff --git a/internal/fourslash/tests/gen/multilineCommentBeforeOpenBrace_test.go b/internal/fourslash/tests/gen/multilineCommentBeforeOpenBrace_test.go new file mode 100644 index 0000000000..a9b56ace97 --- /dev/null +++ b/internal/fourslash/tests/gen/multilineCommentBeforeOpenBrace_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestMultilineCommentBeforeOpenBrace(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function test() /*1*//* %^ */ +{ + if (true) /*2*//* %^ */ + { + } +} +function a() { + /* %^ */ }/*3*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `function test() /* %^ */ {`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` if (true) /* %^ */ {`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `}`) +} diff --git a/internal/fourslash/tests/gen/optionalPropertyFormatting_test.go b/internal/fourslash/tests/gen/optionalPropertyFormatting_test.go new file mode 100644 index 0000000000..0e9f6ffa10 --- /dev/null +++ b/internal/fourslash/tests/gen/optionalPropertyFormatting_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestOptionalPropertyFormatting(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export class C extends Error { + message: string; + data? = {}; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `export class C extends Error { + message: string; + data? = {}; +}`) +} diff --git a/internal/fourslash/tests/gen/paste_test.go b/internal/fourslash/tests/gen/paste_test.go new file mode 100644 index 0000000000..fd8581c7d9 --- /dev/null +++ b/internal/fourslash/tests/gen/paste_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestPaste(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `fn(/**/);` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Paste(t, "x,y,z") + f.VerifyCurrentLineContent(t, `fn(x, y, z);`) +} diff --git a/internal/fourslash/tests/gen/semicolonFormattingAfterArrayLiteral_test.go b/internal/fourslash/tests/gen/semicolonFormattingAfterArrayLiteral_test.go new file mode 100644 index 0000000000..9e2619d54e --- /dev/null +++ b/internal/fourslash/tests/gen/semicolonFormattingAfterArrayLiteral_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSemicolonFormattingAfterArrayLiteral(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `[1,2]/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, `[1, 2];`) +} diff --git a/internal/fourslash/tests/gen/semicolonFormattingInsideAComment_test.go b/internal/fourslash/tests/gen/semicolonFormattingInsideAComment_test.go new file mode 100644 index 0000000000..79c654eb4d --- /dev/null +++ b/internal/fourslash/tests/gen/semicolonFormattingInsideAComment_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSemicolonFormattingInsideAComment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` ///**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, ` //;`) +} diff --git a/internal/fourslash/tests/gen/semicolonFormattingInsideAStringLiteral_test.go b/internal/fourslash/tests/gen/semicolonFormattingInsideAStringLiteral_test.go new file mode 100644 index 0000000000..3f17f54ab0 --- /dev/null +++ b/internal/fourslash/tests/gen/semicolonFormattingInsideAStringLiteral_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSemicolonFormattingInsideAStringLiteral(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` var x = "string/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, ` var x = "string;`) +} diff --git a/internal/fourslash/tests/gen/semicolonFormattingNestedStatements_test.go b/internal/fourslash/tests/gen/semicolonFormattingNestedStatements_test.go new file mode 100644 index 0000000000..93fb8b5676 --- /dev/null +++ b/internal/fourslash/tests/gen/semicolonFormattingNestedStatements_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSemicolonFormattingNestedStatements(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if (true) +if (true)/*parentOutsideBlock*/ +if (true) { +if (true)/*directParent*/ +var x = 0/*innermost*/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "innermost") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, ` var x = 0;`) + f.GoToMarker(t, "directParent") + f.VerifyCurrentLineContent(t, ` if (true)`) + f.GoToMarker(t, "parentOutsideBlock") + f.VerifyCurrentLineContent(t, `if (true)`) +} diff --git a/internal/fourslash/tests/gen/semicolonFormatting_test.go b/internal/fourslash/tests/gen/semicolonFormatting_test.go new file mode 100644 index 0000000000..112d8498dc --- /dev/null +++ b/internal/fourslash/tests/gen/semicolonFormatting_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSemicolonFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/function of1 (b:{r:{c:number` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToEOF(t) + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, `function of1(b: { r: { c: number;`) +} diff --git a/internal/fourslash/tests/gen/singleLineTypeLiteralFormatting_test.go b/internal/fourslash/tests/gen/singleLineTypeLiteralFormatting_test.go new file mode 100644 index 0000000000..23cca40e94 --- /dev/null +++ b/internal/fourslash/tests/gen/singleLineTypeLiteralFormatting_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSingleLineTypeLiteralFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function of1(b: { r: { c: number/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, `function of1(b: { r: { c: number;`) +} diff --git a/internal/fourslash/tests/gen/smartIndentNamedImport_test.go b/internal/fourslash/tests/gen/smartIndentNamedImport_test.go new file mode 100644 index 0000000000..0d5e81bdfb --- /dev/null +++ b/internal/fourslash/tests/gen/smartIndentNamedImport_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSmartIndentNamedImport(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `import {/*0*/ + numbers as bn,/*1*/ + list/*2*/ +} from '@bykov/basics';/*3*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "0") + f.VerifyCurrentLineContent(t, `import {`) + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` numbers as bn,`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` list`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `} from '@bykov/basics';`) +} diff --git a/internal/fourslash/tests/gen/spaceAfterConstructor_test.go b/internal/fourslash/tests/gen/spaceAfterConstructor_test.go new file mode 100644 index 0000000000..301e2c81dd --- /dev/null +++ b/internal/fourslash/tests/gen/spaceAfterConstructor_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSpaceAfterConstructor(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export class myController { + private _processId; + constructor (processId: number) {/*1*/ + this._processId = processId; + }/*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "2") + f.Insert(t, "}") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` constructor(processId: number) {`) +} diff --git a/internal/fourslash/tests/gen/spaceAfterReturn_test.go b/internal/fourslash/tests/gen/spaceAfterReturn_test.go new file mode 100644 index 0000000000..4a6e5130ea --- /dev/null +++ b/internal/fourslash/tests/gen/spaceAfterReturn_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSpaceAfterReturn(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function f( ) { +return 1;/*1*/ +return[1];/*2*/ +return ;/*3*/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, ` return 1;`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, ` return [1];`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, ` return;`) +} diff --git a/internal/fourslash/tests/gen/spaceAfterStatementConditions_test.go b/internal/fourslash/tests/gen/spaceAfterStatementConditions_test.go new file mode 100644 index 0000000000..5fb72f61a3 --- /dev/null +++ b/internal/fourslash/tests/gen/spaceAfterStatementConditions_test.go @@ -0,0 +1,61 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSpaceAfterStatementConditions(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let i = 0; + +if(i<0) ++i; +if(i<0) --i; + +while(i<0) ++i; +while(i<0) --i; + +do ++i; +while(i<0) +do --i; +while(i<0) + +for(let prop in { foo: 1 }) ++i; +for(let prop in { foo: 1 }) --i; + +for(let foo of [1, 2]) ++i; +for(let foo of [1, 2]) --i; + +for(let j = 0; j < 10; j++) ++i; +for(let j = 0; j < 10; j++) --i; +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, `let i = 0; + +if (i < 0) ++i; +if (i < 0) --i; + +while (i < 0) ++i; +while (i < 0) --i; + +do ++i; +while (i < 0) +do --i; +while (i < 0) + +for (let prop in { foo: 1 }) ++i; +for (let prop in { foo: 1 }) --i; + +for (let foo of [1, 2]) ++i; +for (let foo of [1, 2]) --i; + +for (let j = 0; j < 10; j++) ++i; +for (let j = 0; j < 10; j++) --i; +`) +} diff --git a/internal/fourslash/tests/gen/spaceBeforeAndAfterBinaryOperators_test.go b/internal/fourslash/tests/gen/spaceBeforeAndAfterBinaryOperators_test.go new file mode 100644 index 0000000000..77f67cfff2 --- /dev/null +++ b/internal/fourslash/tests/gen/spaceBeforeAndAfterBinaryOperators_test.go @@ -0,0 +1,38 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSpaceBeforeAndAfterBinaryOperators(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let i = 0; +/*1*/(i++,i++); +/*2*/(i++,++i); +/*3*/(1,2); +/*4*/(i++,2); +/*5*/(i++,i++,++i,i--,2); +let s = 'foo'; +/*6*/for (var i = 0,ii = 2; i < s.length; ii++,i++) { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `(i++, i++);`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `(i++, ++i);`) + f.GoToMarker(t, "3") + f.VerifyCurrentLineContent(t, `(1, 2);`) + f.GoToMarker(t, "4") + f.VerifyCurrentLineContent(t, `(i++, 2);`) + f.GoToMarker(t, "5") + f.VerifyCurrentLineContent(t, `(i++, i++, ++i, i--, 2);`) + f.GoToMarker(t, "6") + f.VerifyCurrentLineContent(t, `for (var i = 0, ii = 2; i < s.length; ii++, i++) {`) +} diff --git a/internal/fourslash/tests/gen/tabbingAfterNewlineInsertedBeforeWhile_test.go b/internal/fourslash/tests/gen/tabbingAfterNewlineInsertedBeforeWhile_test.go new file mode 100644 index 0000000000..dd25f3a8b0 --- /dev/null +++ b/internal/fourslash/tests/gen/tabbingAfterNewlineInsertedBeforeWhile_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTabbingAfterNewlineInsertedBeforeWhile(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function foo() { + /**/while (true) { } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.InsertLine(t, "") + f.VerifyCurrentLineContent(t, ` while (true) { }`) +} diff --git a/internal/fourslash/tests/gen/typeAssertionsFormatting_test.go b/internal/fourslash/tests/gen/typeAssertionsFormatting_test.go new file mode 100644 index 0000000000..7bc0b735d0 --- /dev/null +++ b/internal/fourslash/tests/gen/typeAssertionsFormatting_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTypeAssertionsFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `( < any > publisher);/*1*/ + < any > 3;/*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContent(t, `(publisher);`) + f.GoToMarker(t, "2") + f.VerifyCurrentLineContent(t, `3;`) +} diff --git a/internal/fourslash/tests/gen/unclosedStringLiteralAutoformating_test.go b/internal/fourslash/tests/gen/unclosedStringLiteralAutoformating_test.go new file mode 100644 index 0000000000..5530baa1bb --- /dev/null +++ b/internal/fourslash/tests/gen/unclosedStringLiteralAutoformating_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestUnclosedStringLiteralAutoformating(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = /*1*/"asd/*2*/ +class Foo { + /**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "}") + f.VerifyCurrentLineContent(t, `}`) +} diff --git a/internal/fourslash/tests/gen/whiteSpaceBeforeReturnTypeFormatting_test.go b/internal/fourslash/tests/gen/whiteSpaceBeforeReturnTypeFormatting_test.go new file mode 100644 index 0000000000..0a4953b566 --- /dev/null +++ b/internal/fourslash/tests/gen/whiteSpaceBeforeReturnTypeFormatting_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestWhiteSpaceBeforeReturnTypeFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x: () => string/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContent(t, `var x: () => string;`) +} diff --git a/internal/fourslash/tests/gen/whiteSpaceTrimming2_test.go b/internal/fourslash/tests/gen/whiteSpaceTrimming2_test.go new file mode 100644 index 0000000000..7eaf667222 --- /dev/null +++ b/internal/fourslash/tests/gen/whiteSpaceTrimming2_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestWhiteSpaceTrimming2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let noSubTemplate = ` + "`" + `/* /*1*/` + "`" + `; +let templateHead = ` + "`" + `/* /*2*/${1 + 2}` + "`" + `; +let templateMiddle = ` + "`" + `/* ${1 + 2 /*3*/}` + "`" + `; +let templateTail = ` + "`" + `/* ${1 + 2} /*4*/` + "`" + `;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "\n") + f.GoToMarker(t, "2") + f.Insert(t, "\n") + f.GoToMarker(t, "3") + f.Insert(t, "\n") + f.GoToMarker(t, "4") + f.Insert(t, "\n") + f.VerifyCurrentFileContent(t, "let noSubTemplate = `/* \n`;\nlet templateHead = `/* \n${1 + 2}`;\nlet templateMiddle = `/* ${1 + 2\n }`;\nlet templateTail = `/* ${1 + 2} \n`;") +} diff --git a/internal/fourslash/tests/gen/whiteSpaceTrimming3_test.go b/internal/fourslash/tests/gen/whiteSpaceTrimming3_test.go new file mode 100644 index 0000000000..6c5c4331b8 --- /dev/null +++ b/internal/fourslash/tests/gen/whiteSpaceTrimming3_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestWhiteSpaceTrimming3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let t = "foo \ +bar \ +"/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentFileContent(t, "let t = \"foo \\\nbar \\ \n\";") +} diff --git a/internal/fourslash/tests/gen/whiteSpaceTrimming4_test.go b/internal/fourslash/tests/gen/whiteSpaceTrimming4_test.go new file mode 100644 index 0000000000..703c8124b1 --- /dev/null +++ b/internal/fourslash/tests/gen/whiteSpaceTrimming4_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestWhiteSpaceTrimming4(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var re = /\w+ /*1*//;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "\n") + f.VerifyCurrentFileContent(t, "var re = /\\w+\n /;") +} diff --git a/internal/fourslash/tests/gen/whiteSpaceTrimming_test.go b/internal/fourslash/tests/gen/whiteSpaceTrimming_test.go new file mode 100644 index 0000000000..039ff9ac90 --- /dev/null +++ b/internal/fourslash/tests/gen/whiteSpaceTrimming_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestWhiteSpaceTrimming(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if (true) { + // + /*err*/}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "err") + f.Insert(t, "\n") + f.VerifyCurrentFileContent(t, `if (true) { + // + +}`) +} diff --git a/internal/ls/format.go b/internal/ls/format.go index 0b14f57e33..355a44ac68 100644 --- a/internal/ls/format.go +++ b/internal/ls/format.go @@ -13,20 +13,6 @@ import ( "github.com/microsoft/typescript-go/internal/scanner" ) -func toFormatCodeSettings(opt *lsproto.FormattingOptions) *lsutil.FormatCodeSettings { - initial := lsutil.GetDefaultFormatCodeSettings() - initial.TabSize = int(opt.TabSize) - initial.IndentSize = int(opt.TabSize) - initial.ConvertTabsToSpaces = opt.InsertSpaces - if opt.TrimTrailingWhitespace != nil { - initial.TrimTrailingWhitespace = *opt.TrimTrailingWhitespace - } - - // !!! get format settings - // TODO: We support a _lot_ more options than this - return initial -} - func (l *LanguageService) toLSProtoTextEdits(file *ast.SourceFile, changes []core.TextChange) []*lsproto.TextEdit { result := make([]*lsproto.TextEdit, 0, len(changes)) for _, c := range changes { @@ -47,7 +33,7 @@ func (l *LanguageService) ProvideFormatDocument( edits := l.toLSProtoTextEdits(file, l.getFormattingEditsForDocument( ctx, file, - toFormatCodeSettings(options), + lsutil.FromLSFormatOptions(l.UserPreferences().FormatCodeSettings, options), )) return lsproto.TextEditsOrNull{TextEdits: &edits}, nil } @@ -62,7 +48,7 @@ func (l *LanguageService) ProvideFormatDocumentRange( edits := l.toLSProtoTextEdits(file, l.getFormattingEditsForRange( ctx, file, - toFormatCodeSettings(options), + lsutil.FromLSFormatOptions(l.UserPreferences().FormatCodeSettings, options), l.converters.FromLSPRange(file, r), )) return lsproto.TextEditsOrNull{TextEdits: &edits}, nil @@ -79,7 +65,7 @@ func (l *LanguageService) ProvideFormatDocumentOnType( edits := l.toLSProtoTextEdits(file, l.getFormattingEditsAfterKeystroke( ctx, file, - toFormatCodeSettings(options), + lsutil.FromLSFormatOptions(l.UserPreferences().FormatCodeSettings, options), int(l.converters.LineAndCharacterToPosition(file, position)), character, )) diff --git a/internal/ls/lsutil/formatcodeoptions.go b/internal/ls/lsutil/formatcodeoptions.go index 04cf14c1e5..a62c6c27d6 100644 --- a/internal/ls/lsutil/formatcodeoptions.go +++ b/internal/ls/lsutil/formatcodeoptions.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/microsoft/typescript-go/internal/core" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" "github.com/microsoft/typescript-go/internal/tsoptions" ) @@ -86,6 +87,25 @@ type FormatCodeSettings struct { IndentSwitchCase core.Tristate } +func FromLSFormatOptions(f *FormatCodeSettings, opt *lsproto.FormattingOptions) *FormatCodeSettings { + updatedSettings := f.Copy() + updatedSettings.TabSize = int(opt.TabSize) + updatedSettings.IndentSize = int(opt.TabSize) + updatedSettings.ConvertTabsToSpaces = opt.InsertSpaces + if opt.TrimTrailingWhitespace != nil { + updatedSettings.TrimTrailingWhitespace = *opt.TrimTrailingWhitespace + } + return updatedSettings +} + +func (settings *FormatCodeSettings) ToLSFormatOptions() *lsproto.FormattingOptions { + return &lsproto.FormattingOptions{ + TabSize: uint32(settings.TabSize), + InsertSpaces: settings.ConvertTabsToSpaces, + TrimTrailingWhitespace: &settings.TrimTrailingWhitespace, + } +} + func (settings *FormatCodeSettings) Parse(prefs any) bool { formatSettingsMap, ok := prefs.(map[string]any) formatSettingsParsed := false diff --git a/internal/ls/lsutil/userpreferences.go b/internal/ls/lsutil/userpreferences.go index e6e775f96b..f934790768 100644 --- a/internal/ls/lsutil/userpreferences.go +++ b/internal/ls/lsutil/userpreferences.go @@ -28,7 +28,7 @@ func NewDefaultUserPreferences() *UserPreferences { } type UserPreferences struct { - *FormatCodeSettings + FormatCodeSettings *FormatCodeSettings QuotePreference QuotePreference LazyConfiguredProjectsFromExternalProject bool // !!! @@ -380,7 +380,7 @@ func (p *UserPreferences) ParseWorker(config map[string]any) *UserPreferences { // Process unstable preferences first so that they do not overwrite stable properties if unstable, ok := config["unstable"]; ok { // unstable properties must be named the same as userPreferences - p.ParseAll(unstable) + p.parseAll(unstable) } formatSettingsParsed := false for name, values := range config { @@ -388,15 +388,15 @@ func (p *UserPreferences) ParseWorker(config map[string]any) *UserPreferences { case "unstable": continue case "inlayHints": - p.ParseInlayHints(values) + p.parseInlayHints(values) case "referencesCodeLens": p.parseReferencesCodeLens(values) case "implementationsCodeLens": p.parseImplementationsCodeLens(values) case "suggest": - p.ParseSuggest(values) + p.parseSuggest(values) case "preferences": - p.ParsePreferences(values) + p.parsePreferences(values) case "workspaceSymbols": p.parseWorkspaceSymbols(values) case "format": @@ -424,7 +424,7 @@ func (p *UserPreferences) parseAll(prefs any) { return } for name, value := range prefsMap { - p.set(name, value) + p.Set(name, value) } } @@ -439,7 +439,7 @@ func (p *UserPreferences) parseInlayHints(prefs any) { switch name { case "parameterNames": if enabled, ok := v["enabled"]; ok { - p.set("includeInlayParameterNameHints", enabled) + p.Set("includeInlayParameterNameHints", enabled) } p.InlayHints.IncludeInlayParameterNameHintsWhenArgumentMatchesName = parseSuppress(v, "suppressWhenArgumentMatchesName") case "parameterTypes": @@ -456,7 +456,7 @@ func (p *UserPreferences) parseInlayHints(prefs any) { } } else { // non-vscode case - p.set(name, v) + p.Set(name, v) } } } @@ -469,9 +469,9 @@ func (p *UserPreferences) parseReferencesCodeLens(prefs any) { for name, value := range referencesCodeLens { switch name { case "enabled": - p.set("referencesCodeLensEnabled", value) + p.Set("referencesCodeLensEnabled", value) case "showOnAllFunctions": - p.set("referencesCodeLensShowOnAllFunctions", value) + p.Set("referencesCodeLensShowOnAllFunctions", value) } } } @@ -484,11 +484,11 @@ func (p *UserPreferences) parseImplementationsCodeLens(prefs any) { for name, value := range implementationsCodeLens { switch name { case "enabled": - p.set("implementationsCodeLensEnabled", value) + p.Set("implementationsCodeLensEnabled", value) case "showOnInterfaceMethods": - p.set("implementationsCodeLensShowOnInterfaceMethods", value) + p.Set("implementationsCodeLensShowOnInterfaceMethods", value) case "showOnAllClassMethods": - p.set("implementationsCodeLensShowOnAllClassMethods", value) + p.Set("implementationsCodeLensShowOnAllClassMethods", value) } } } @@ -501,19 +501,19 @@ func (p *UserPreferences) parseSuggest(prefs any) { for name, value := range completionsPreferences { switch name { case "autoImports": - p.set("includeCompletionsForModuleExports", value) + p.Set("includeCompletionsForModuleExports", value) case "objectLiteralMethodSnippets": if v, ok := value.(map[string]any); ok { - p.set("includeCompletionsWithObjectLiteralMethodSnippets", parseEnabledBool(v)) + p.Set("includeCompletionsWithObjectLiteralMethodSnippets", parseEnabledBool(v)) } case "classMemberSnippets": if v, ok := value.(map[string]any); ok { - p.set("includeCompletionsWithClassMemberSnippets", parseEnabledBool(v)) + p.Set("includeCompletionsWithClassMemberSnippets", parseEnabledBool(v)) } case "includeAutomaticOptionalChainCompletions": - p.set("includeAutomaticOptionalChainCompletions", value) + p.Set("includeAutomaticOptionalChainCompletions", value) case "includeCompletionsForImportStatements": - p.set("includeCompletionsForImportStatements", value) + p.Set("includeCompletionsForImportStatements", value) } } } @@ -527,7 +527,7 @@ func (p *UserPreferences) parsePreferences(prefs any) { if name == "organizeImports" { p.parseOrganizeImportsPreferences(value) } else { - p.set(name, value) + p.Set(name, value) } } } @@ -539,7 +539,7 @@ func (p *UserPreferences) parseOrganizeImportsPreferences(prefs any) { return } if typeOrder, ok := prefsMap["typeOrder"]; ok { - p.set("organizeimportstypeorder", parseOrganizeImportsTypeOrder(typeOrder)) + p.Set("organizeimportstypeorder", parseOrganizeImportsTypeOrder(typeOrder)) } if caseSensitivity, ok := prefsMap["caseSensitivity"]; ok { if caseSensitivityStr, ok := caseSensitivity.(string); ok { @@ -555,18 +555,18 @@ func (p *UserPreferences) parseOrganizeImportsPreferences(prefs any) { if collation, ok := prefsMap["unicodeCollation"]; ok { // The rest of the settings are only applicable when using unicode collation if collationStr, ok := collation.(string); ok && collationStr == "unicode" { - p.set("organizeimportscollation", OrganizeImportsCollationUnicode) + p.Set("organizeimportscollation", OrganizeImportsCollationUnicode) if locale, ok := prefsMap["locale"]; ok { - p.set("organizeimportslocale", locale) + p.Set("organizeimportslocale", locale) } if numeric, ok := prefsMap["numericCollation"]; ok { - p.set("organizeimportsnumericcollation", numeric) + p.Set("organizeimportsnumericcollation", numeric) } if accent, ok := prefsMap["accentCollation"]; ok { - p.set("organizeimportsaccentcollation", accent) + p.Set("organizeimportsaccentcollation", accent) } if caseFirst, ok := prefsMap["caseFirst"]; ok && !p.OrganizeImportsIgnoreCase.IsTrue() { - p.set("organizeimportscasefirst", caseFirst) + p.Set("organizeimportscasefirst", caseFirst) } } } @@ -583,7 +583,7 @@ func (p *UserPreferences) parseWorkspaceSymbols(prefs any) { case "excludeLibrarySymbols": p.ExcludeLibrarySymbolsInNavTo = parseBoolWithDefault(value, true) default: - p.set(name, value) + p.Set(name, value) } } } @@ -622,7 +622,7 @@ func parseIntWithDefault(val any, defaultV int) int { return defaultV } -func (p *UserPreferences) set(name string, value any) bool { +func (p *UserPreferences) Set(name string, value any) bool { switch strings.ToLower(name) { case "quotePreference": p.QuotePreference = parseQuotePreference(value) @@ -722,125 +722,3 @@ func (p *UserPreferences) set(name string, value any) bool { } return true } - -func (p *UserPreferences) ParseOrganizeImportsPreferences(prefs any) { - // !!! this used to be in the typescript-language-features extension - prefsMap, ok := prefs.(map[string]any) - if !ok { - return - } - if typeOrder, ok := prefsMap["typeOrder"]; ok { - p.Set("organizeimportstypeorder", parseOrganizeImportsTypeOrder(typeOrder)) - } - if caseSensitivity, ok := prefsMap["caseSensitivity"]; ok { - if caseSensitivityStr, ok := caseSensitivity.(string); ok { - // default is already "auto" - switch caseSensitivityStr { - case "caseInsensitive": - p.OrganizeImportsIgnoreCase = core.TSTrue - case "caseSensitive": - p.OrganizeImportsIgnoreCase = core.TSFalse - } - } - } - if collation, ok := prefsMap["unicodeCollation"]; ok { - // The rest of the settings are only applicable when using unicode collation - if collationStr, ok := collation.(string); ok && collationStr == "unicode" { - p.Set("organizeimportscollation", OrganizeImportsCollationUnicode) - if locale, ok := prefsMap["locale"]; ok { - p.Set("organizeimportslocale", locale) - } - if numeric, ok := prefsMap["numericCollation"]; ok { - p.Set("organizeimportsnumericcollation", numeric) - } - if accent, ok := prefsMap["accentCollation"]; ok { - p.Set("organizeimportsaccentcollation", accent) - } - if caseFirst, ok := prefsMap["caseFirst"]; ok && !p.OrganizeImportsIgnoreCase.IsTrue() { - p.Set("organizeimportscasefirst", caseFirst) - } - } - } -} - -func (p *UserPreferences) ParseAll(prefs any) { - prefsMap, ok := prefs.(map[string]any) - if !ok { - return - } - for name, value := range prefsMap { - p.Set(name, value) - } -} - -func (p *UserPreferences) ParseInlayHints(prefs any) { - inlayHintsPreferences, ok := prefs.(map[string]any) - if !ok { - return - } - for name, value := range inlayHintsPreferences { - if v, ok := value.(map[string]any); ok { - // vscode's inlay hints settings are nested objects with "enabled" and other properties - switch name { - case "parameterNames": - if enabled, ok := v["enabled"]; ok { - p.Set("includeInlayParameterNameHints", enabled) - } - p.InlayHints.IncludeInlayParameterNameHintsWhenArgumentMatchesName = parseSuppress(v, "supressWhenArgumentMatchesName") - case "parameterTypes": - p.InlayHints.IncludeInlayFunctionParameterTypeHints = parseEnabledBool(v) - case "variableTypes": - p.InlayHints.IncludeInlayVariableTypeHints = parseEnabledBool(v) - p.InlayHints.IncludeInlayVariableTypeHintsWhenTypeMatchesName = parseSuppress(v, "supressWhenTypeMatchesName") - case "propertyDeclarationTypes": - p.InlayHints.IncludeInlayPropertyDeclarationTypeHints = parseEnabledBool(v) - case "functionLikeReturnTypes": - p.InlayHints.IncludeInlayFunctionLikeReturnTypeHints = parseEnabledBool(v) - case "enumMemberValues": - p.InlayHints.IncludeInlayEnumMemberValueHints = parseEnabledBool(v) - } - } else { - // non-vscode case - p.Set(name, v) - } - } -} - -func (p *UserPreferences) ParseSuggest(prefs any) { - completionsPreferences, ok := prefs.(map[string]any) - if !ok { - return - } - for name, value := range completionsPreferences { - switch name { - case "autoImports": - p.Set("includeCompletionsForModuleExports", value) - case "objectLiteralMethodSnippets": - if v, ok := value.(map[string]any); ok { - p.Set("includeCompletionsWithObjectLiteralMethodSnippets", parseEnabledBool(v)) - } - case "classMemberSnippets": - if v, ok := value.(map[string]any); ok { - p.Set("includeCompletionsWithClassMemberSnippets", parseEnabledBool(v)) - } - case "includeAutomaticOptionalChainCompletions": - p.Set("includeAutomaticOptionalChainCompletions", value) - case "includeCompletionsForImportStatements": - p.Set("includeCompletionsForImportStatements", value) - } - } -} - -func (p *UserPreferences) ParsePreferences(prefs any) { - prefsMap, ok := prefs.(map[string]any) - if !ok { - return - } - for name, value := range prefsMap { - if name == "organizeImports" { - p.ParseOrganizeImportsPreferences(value) - } else { - p.Set(name, value) - } - } -} diff --git a/internal/project/configuration.go b/internal/project/configuration.go index 7c49b5aec5..797fde9512 100644 --- a/internal/project/configuration.go +++ b/internal/project/configuration.go @@ -6,7 +6,7 @@ import ( type Config struct { js *lsutil.UserPreferences - ts *lsutil.UserPreferences + Ts *lsutil.UserPreferences // tsserverOptions } @@ -14,21 +14,21 @@ func NewConfig(userPreferences *lsutil.UserPreferences) *Config { // use default userPreferences if nil return &Config{ js: userPreferences.CopyOrDefault(), - ts: userPreferences.CopyOrDefault(), + Ts: userPreferences.CopyOrDefault(), } } func (c *Config) Copy() *Config { return &Config{ - ts: c.ts.CopyOrDefault(), + Ts: c.Ts.CopyOrDefault(), js: c.js.CopyOrDefault(), } } // any non-nil field in b is copied into a func (a *Config) CopyInto(b *Config) *Config { - if b.ts != nil { - a.ts = b.ts.Copy() + if b.Ts != nil { + a.Ts = b.Ts.Copy() } if b.js != nil { a.js = b.js.Copy() @@ -45,7 +45,7 @@ func ParseConfiguration(items []any) *Config { } else if config, ok := item.(map[string]any); ok { newConfig := &Config{} if i < 2 { - newConfig.ts = defaultConfig.ts.Copy().ParseWorker(config) + newConfig.Ts = defaultConfig.Ts.Copy().ParseWorker(config) } else { newConfig.js = defaultConfig.js.Copy().ParseWorker(config) } diff --git a/internal/project/session.go b/internal/project/session.go index e801737c6e..0aef9b6575 100644 --- a/internal/project/session.go +++ b/internal/project/session.go @@ -167,8 +167,8 @@ func NewSession(init *SessionInit) *Session { nil, toPath, ), - initialConfig: &Config{}, - workspaceConfig: &Config{}, + initialConfig: NewConfig(nil), + workspaceConfig: NewConfig(nil), // initialize so all `config`s are non-nil pendingATAChanges: make(map[tspath.Path]*ATAStateChange), watches: make(map[fileSystemWatcherKey]*fileSystemWatcherValue), } @@ -193,25 +193,25 @@ func (s *Session) GetCurrentDirectory() string { return s.options.CurrentDirectory } -// Gets current configuration, always a copy -func (s *Session) Config() Config { +// Gets copy of current configuration +func (s *Session) Config() *Config { s.configRWMu.Lock() defer s.configRWMu.Unlock() - return *s.workspaceConfig.Copy() + return s.workspaceConfig.Copy() } // !!! ts/js preferences -// Gets current configuration, always a copy +// Gets copy of current UserPreferences func (s *Session) UserPreferences() *lsutil.UserPreferences { s.configRWMu.Lock() defer s.configRWMu.Unlock() - return s.workspaceConfig.ts.Copy() + return s.workspaceConfig.Ts.Copy() } // !!! ts/js preferences // Gets original UserPreferences of the session func (s *Session) NewUserPreferences() *lsutil.UserPreferences { - return s.initialConfig.ts.CopyOrDefault() + return s.initialConfig.Ts.CopyOrDefault() } // Trace implements module.ResolutionHost @@ -220,21 +220,23 @@ func (s *Session) Trace(msg string) { } func (s *Session) Configure(config *Config) { + // `config` should never be nil s.configRWMu.Lock() defer s.configRWMu.Unlock() s.pendingConfigChanges = true - oldConfig := s.workspaceConfig + oldConfig := s.workspaceConfig.Copy() s.workspaceConfig = s.workspaceConfig.CopyInto(config) // Tell the client to re-request certain commands depending on user preference changes. - if oldUserPreferences != config && oldUserPreferences != nil && config != nil { - s.refreshInlayHintsIfNeeded(oldUserPreferences, config) - s.refreshCodeLensIfNeeded(oldUserPreferences, config) + if oldConfig != config { + + s.refreshInlayHintsIfNeeded(oldConfig, config) + s.refreshCodeLensIfNeeded(oldConfig, config) } } func (s *Session) InitializeWithConfig(config *Config) { - config.ts = config.ts.CopyOrDefault() + config.Ts = config.Ts.CopyOrDefault() s.initialConfig = config s.Configure(s.initialConfig) } @@ -806,16 +808,16 @@ func (s *Session) NpmInstall(cwd string, npmInstallArgs []string) ([]byte, error return s.npmExecutor.NpmInstall(cwd, npmInstallArgs) } -func (s *Session) refreshInlayHintsIfNeeded(oldPrefs *lsutil.UserPreferences, newPrefs *lsutil.UserPreferences) { - if oldPrefs.InlayHints != newPrefs.InlayHints { +func (s *Session) refreshInlayHintsIfNeeded(oldPrefs *Config, newPrefs *Config) { + if oldPrefs.js.InlayHints != newPrefs.js.InlayHints || oldPrefs.Ts.InlayHints != newPrefs.Ts.InlayHints { if err := s.client.RefreshInlayHints(context.Background()); err != nil && s.options.LoggingEnabled { s.logger.Logf("Error refreshing inlay hints: %v", err) } } } -func (s *Session) refreshCodeLensIfNeeded(oldPrefs *lsutil.UserPreferences, newPrefs *lsutil.UserPreferences) { - if oldPrefs.CodeLens != newPrefs.CodeLens { +func (s *Session) refreshCodeLensIfNeeded(oldPrefs *Config, newPrefs *Config) { + if oldPrefs.js.CodeLens != newPrefs.js.CodeLens || oldPrefs.Ts.CodeLens != newPrefs.Ts.CodeLens { if err := s.client.RefreshCodeLens(context.Background()); err != nil && s.options.LoggingEnabled { s.logger.Logf("Error refreshing code lens: %v", err) } diff --git a/internal/project/session_test.go b/internal/project/session_test.go index b1ffed559e..c02431c17a 100644 --- a/internal/project/session_test.go +++ b/internal/project/session_test.go @@ -9,7 +9,6 @@ import ( "github.com/microsoft/typescript-go/internal/bundled" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/glob" - "github.com/microsoft/typescript-go/internal/ls/lsutil" "github.com/microsoft/typescript-go/internal/lsp/lsproto" "github.com/microsoft/typescript-go/internal/project" "github.com/microsoft/typescript-go/internal/testutil/projecttestutil" @@ -863,13 +862,13 @@ func TestSession(t *testing.T) { _, err := session.GetLanguageService(context.Background(), lsproto.DocumentUri("file:///src/index.ts")) assert.NilError(t, err) - session.Configure(&lsutil.UserPreferences{}) - + session.Configure(project.NewConfig(nil)) // Change user preferences for code lens and inlay hints. newPrefs := session.UserPreferences() newPrefs.CodeLens.ReferencesCodeLensEnabled = !newPrefs.CodeLens.ReferencesCodeLensEnabled newPrefs.InlayHints.IncludeInlayFunctionLikeReturnTypeHints = !newPrefs.InlayHints.IncludeInlayFunctionLikeReturnTypeHints - session.Configure(newPrefs) + + session.Configure(project.NewConfig(newPrefs)) codeLensRefreshCalls := utils.Client().RefreshCodeLensCalls() inlayHintsRefreshCalls := utils.Client().RefreshInlayHintsCalls() diff --git a/internal/project/snapshot.go b/internal/project/snapshot.go index 96d1d8876f..9ba9921dff 100644 --- a/internal/project/snapshot.go +++ b/internal/project/snapshot.go @@ -106,11 +106,11 @@ func (s *Snapshot) GetECMALineInfo(fileName string) *sourcemap.ECMALineInfo { } func (s *Snapshot) UserPreferences() *lsutil.UserPreferences { - return s.config.ts + return s.config.Ts } func (s *Snapshot) FormatOptions() *lsutil.FormatCodeSettings { - return s.config.ts.FormatCodeSettings + return s.config.Ts.FormatCodeSettings } func (s *Snapshot) Converters() *lsconv.Converters { diff --git a/internal/scanner/scanner.go b/internal/scanner/scanner.go index 0367bd0214..50f44fb91b 100644 --- a/internal/scanner/scanner.go +++ b/internal/scanner/scanner.go @@ -2459,7 +2459,7 @@ func GetECMAEndLinePosition(sourceFile *ast.SourceFile, line int) int { for { ch, size := utf8.DecodeRuneInString(sourceFile.Text()[pos:]) if size == 0 || stringutil.IsLineBreak(ch) { - return pos + return pos - 1 } pos += size } diff --git a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithDisableSourceOfProjectReferenceRedirectEdit.baseline b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithDisableSourceOfProjectReferenceRedirectEdit.baseline index 2d9b7d45c9..d3f5f4d2f8 100644 --- a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithDisableSourceOfProjectReferenceRedirectEdit.baseline +++ b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithDisableSourceOfProjectReferenceRedirectEdit.baseline @@ -353,6 +353,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 1 + }, + "ch": "f", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -378,6 +405,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 2 + }, + "ch": "u", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -403,6 +457,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 3 + }, + "ch": "n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -428,6 +509,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 4 + }, + "ch": "c", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -453,6 +561,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 5 + }, + "ch": "t", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -478,6 +613,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 6 + }, + "ch": "i", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -503,6 +665,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 7 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -528,6 +717,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 8 + }, + "ch": "n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -553,6 +769,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 9 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -578,6 +821,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 10 + }, + "ch": "f", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -603,6 +873,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 11 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -628,6 +925,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 12 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -653,6 +977,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 13 + }, + "ch": "B", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -678,6 +1029,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 14 + }, + "ch": "a", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -703,6 +1081,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 15 + }, + "ch": "r", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -728,6 +1133,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 16 + }, + "ch": "(", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -753,6 +1185,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 17 + }, + "ch": ")", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -778,6 +1237,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 18 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -803,6 +1289,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 19 + }, + "ch": "{", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -828,6 +1341,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 20 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -853,6 +1393,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 21 + }, + "ch": "}", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -872,12 +1439,89 @@ Config:: "character": 21 } }, + "text": " " + } + ] + } +} + +{ + "method": "textDocument/didChange", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts", + "version": 25 + }, + "contentChanges": [ + { + "range": { + "start": { + "line": 0, + "character": 22 + }, + "end": { + "line": 0, + "character": 22 + } + }, "text": "\n" } ] } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 1, + "character": 0 + }, + "ch": "\n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + +{ + "method": "textDocument/didChange", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts", + "version": 26 + }, + "contentChanges": [ + { + "range": { + "start": { + "line": 0, + "character": 21 + }, + "end": { + "line": 0, + "character": 22 + } + }, + "text": "" + } + ] + } +} + { "method": "textDocument/rename", "params": { diff --git a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithDisableSourceOfProjectReferenceRedirectEditEnd.baseline b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithDisableSourceOfProjectReferenceRedirectEditEnd.baseline index 4a3267804a..8b6adb16bb 100644 --- a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithDisableSourceOfProjectReferenceRedirectEditEnd.baseline +++ b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithDisableSourceOfProjectReferenceRedirectEditEnd.baseline @@ -353,6 +353,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 1 + }, + "ch": "c", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -378,6 +405,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 2 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -403,6 +457,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 3 + }, + "ch": "n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -428,6 +509,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 4 + }, + "ch": "s", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -453,6 +561,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 5 + }, + "ch": "t", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -478,6 +613,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 6 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -503,6 +665,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 7 + }, + "ch": "x", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -528,6 +717,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 8 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -553,6 +769,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 9 + }, + "ch": "=", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -578,6 +821,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 10 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -603,6 +873,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 11 + }, + "ch": "1", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -628,6 +925,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 12 + }, + "ch": "0", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -654,16 +978,21 @@ Config:: } { - "method": "textDocument/rename", + "method": "textDocument/onTypeFormatting", "params": { "textDocument": { "uri": "file:///myproject/dependency/FnS.ts" }, "position": { - "line": 2, - "character": 16 + "line": 5, + "character": 13 }, - "newName": "?" + "ch": ";", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } } } @@ -675,6 +1004,20 @@ Projects:: /myproject/main/main.ts [/myproject/tsconfig.json] +{ + "method": "textDocument/rename", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 2, + "character": 16 + }, + "newName": "?" + } +} + diff --git a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithProjectReferencesEdit.baseline b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithProjectReferencesEdit.baseline index 9e647c2c2f..72b1aed84a 100644 --- a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithProjectReferencesEdit.baseline +++ b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithProjectReferencesEdit.baseline @@ -203,6 +203,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 1 + }, + "ch": "f", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -228,6 +255,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 2 + }, + "ch": "u", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -253,6 +307,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 3 + }, + "ch": "n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -278,6 +359,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 4 + }, + "ch": "c", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -303,6 +411,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 5 + }, + "ch": "t", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -328,6 +463,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 6 + }, + "ch": "i", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -353,6 +515,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 7 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -378,6 +567,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 8 + }, + "ch": "n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -403,6 +619,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 9 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -428,6 +671,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 10 + }, + "ch": "f", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -453,6 +723,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 11 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -478,6 +775,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 12 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -503,6 +827,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 13 + }, + "ch": "B", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -528,6 +879,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 14 + }, + "ch": "a", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -553,6 +931,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 15 + }, + "ch": "r", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -578,6 +983,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 16 + }, + "ch": "(", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -603,6 +1035,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 17 + }, + "ch": ")", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -628,6 +1087,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 18 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -653,6 +1139,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 19 + }, + "ch": "{", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -678,6 +1191,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 20 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -703,6 +1243,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 21 + }, + "ch": "}", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -722,12 +1289,89 @@ Config:: "character": 21 } }, + "text": " " + } + ] + } +} + +{ + "method": "textDocument/didChange", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts", + "version": 25 + }, + "contentChanges": [ + { + "range": { + "start": { + "line": 0, + "character": 22 + }, + "end": { + "line": 0, + "character": 22 + } + }, "text": "\n" } ] } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 1, + "character": 0 + }, + "ch": "\n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + +{ + "method": "textDocument/didChange", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts", + "version": 26 + }, + "contentChanges": [ + { + "range": { + "start": { + "line": 0, + "character": 21 + }, + "end": { + "line": 0, + "character": 22 + } + }, + "text": "" + } + ] + } +} + { "method": "textDocument/rename", "params": { diff --git a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithProjectReferencesEditEnd.baseline b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithProjectReferencesEditEnd.baseline index 13e6ff1734..d004d16e76 100644 --- a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithProjectReferencesEditEnd.baseline +++ b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithProjectReferencesEditEnd.baseline @@ -203,6 +203,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 1 + }, + "ch": "c", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -228,6 +255,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 2 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -253,6 +307,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 3 + }, + "ch": "n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -278,6 +359,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 4 + }, + "ch": "s", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -303,6 +411,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 5 + }, + "ch": "t", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -328,6 +463,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 6 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -353,6 +515,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 7 + }, + "ch": "x", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -378,6 +567,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 8 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -403,6 +619,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 9 + }, + "ch": "=", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -428,6 +671,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 10 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -453,6 +723,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 11 + }, + "ch": "1", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -478,6 +775,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 12 + }, + "ch": "0", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -503,6 +827,33 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 13 + }, + "ch": ";", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + { "method": "textDocument/rename", "params": { @@ -518,8 +869,8 @@ Config:: } Projects:: - [/myproject/dependency/tsconfig.json] *modified* - /myproject/dependency/FnS.ts *modified* + [/myproject/dependency/tsconfig.json] + /myproject/dependency/FnS.ts [/myproject/main/tsconfig.json] *modified* /myproject/dependency/FnS.ts *modified* /myproject/main/main.ts diff --git a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsEdit.baseline b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsEdit.baseline index 964d19c2e6..aaccdf1350 100644 --- a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsEdit.baseline +++ b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsEdit.baseline @@ -333,6 +333,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 1 + }, + "ch": "f", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -358,6 +382,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 2 + }, + "ch": "u", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -383,6 +431,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 3 + }, + "ch": "n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -408,6 +480,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 4 + }, + "ch": "c", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -433,6 +529,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 5 + }, + "ch": "t", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -458,6 +578,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 6 + }, + "ch": "i", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -483,6 +627,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 7 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -508,6 +676,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 8 + }, + "ch": "n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -533,6 +725,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 9 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -558,6 +774,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 10 + }, + "ch": "f", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -583,6 +823,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 11 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -608,6 +872,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 12 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -633,6 +921,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 13 + }, + "ch": "B", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -658,6 +970,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 14 + }, + "ch": "a", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -683,6 +1019,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 15 + }, + "ch": "r", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -708,6 +1068,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 16 + }, + "ch": "(", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -733,6 +1117,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 17 + }, + "ch": ")", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -758,6 +1166,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 18 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -783,6 +1215,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 19 + }, + "ch": "{", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -808,6 +1264,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 20 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -833,6 +1313,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 21 + }, + "ch": "}", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -852,12 +1356,86 @@ Config:: "character": 21 } }, + "text": " " + } + ] + } +} + +{ + "method": "textDocument/didChange", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts", + "version": 25 + }, + "contentChanges": [ + { + "range": { + "start": { + "line": 0, + "character": 22 + }, + "end": { + "line": 0, + "character": 22 + } + }, "text": "\n" } ] } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 1, + "character": 0 + }, + "ch": "\n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + +{ + "method": "textDocument/didChange", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts", + "version": 26 + }, + "contentChanges": [ + { + "range": { + "start": { + "line": 0, + "character": 21 + }, + "end": { + "line": 0, + "character": 22 + } + }, + "text": "" + } + ] + } +} + { "method": "textDocument/rename", "params": { diff --git a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsEditEnd.baseline b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsEditEnd.baseline index 98b9e58e70..91e59d13ba 100644 --- a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsEditEnd.baseline +++ b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsEditEnd.baseline @@ -333,6 +333,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 1 + }, + "ch": "c", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -358,6 +382,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 2 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -383,6 +431,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 3 + }, + "ch": "n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -408,6 +480,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 4 + }, + "ch": "s", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -433,6 +529,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 5 + }, + "ch": "t", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -458,6 +578,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 6 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -483,6 +627,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 7 + }, + "ch": "x", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -508,6 +676,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 8 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -533,6 +725,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 9 + }, + "ch": "=", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -558,6 +774,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 10 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -583,6 +823,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 11 + }, + "ch": "1", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -608,6 +872,30 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 12 + }, + "ch": "0", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/tsconfig.json] + { "method": "textDocument/didChange", "params": { @@ -634,16 +922,21 @@ Config:: } { - "method": "textDocument/rename", + "method": "textDocument/onTypeFormatting", "params": { "textDocument": { "uri": "file:///myproject/dependency/FnS.ts" }, "position": { - "line": 2, - "character": 16 + "line": 5, + "character": 13 }, - "newName": "?" + "ch": ";", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } } } @@ -652,6 +945,20 @@ Projects:: /myproject/dependency/FnS.ts *modified* [/myproject/tsconfig.json] +{ + "method": "textDocument/rename", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 2, + "character": 16 + }, + "newName": "?" + } +} + diff --git a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsNotSolutionEdit.baseline b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsNotSolutionEdit.baseline index 8525100948..c61bb0a0c5 100644 --- a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsNotSolutionEdit.baseline +++ b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsNotSolutionEdit.baseline @@ -358,6 +358,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 1 + }, + "ch": "f", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -383,6 +412,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 2 + }, + "ch": "u", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -408,6 +466,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 3 + }, + "ch": "n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -433,6 +520,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 4 + }, + "ch": "c", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -458,6 +574,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 5 + }, + "ch": "t", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -483,6 +628,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 6 + }, + "ch": "i", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -508,6 +682,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 7 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -533,6 +736,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 8 + }, + "ch": "n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -558,6 +790,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 9 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -583,6 +844,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 10 + }, + "ch": "f", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -608,6 +898,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 11 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -633,6 +952,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 12 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -658,6 +1006,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 13 + }, + "ch": "B", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -683,6 +1060,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 14 + }, + "ch": "a", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -708,6 +1114,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 15 + }, + "ch": "r", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -733,6 +1168,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 16 + }, + "ch": "(", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -758,6 +1222,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 17 + }, + "ch": ")", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -783,6 +1276,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 18 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -808,6 +1330,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 19 + }, + "ch": "{", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -833,6 +1384,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 20 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -858,6 +1438,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 0, + "character": 21 + }, + "ch": "}", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -877,12 +1486,91 @@ Config:: "character": 21 } }, + "text": " " + } + ] + } +} + +{ + "method": "textDocument/didChange", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts", + "version": 25 + }, + "contentChanges": [ + { + "range": { + "start": { + "line": 0, + "character": 22 + }, + "end": { + "line": 0, + "character": 22 + } + }, "text": "\n" } ] } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 1, + "character": 0 + }, + "ch": "\n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + +{ + "method": "textDocument/didChange", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts", + "version": 26 + }, + "contentChanges": [ + { + "range": { + "start": { + "line": 0, + "character": 21 + }, + "end": { + "line": 0, + "character": 22 + } + }, + "text": "" + } + ] + } +} + { "method": "textDocument/rename", "params": { diff --git a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsNotSolutionEditEnd.baseline b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsNotSolutionEditEnd.baseline index f923c0fdbb..6e5c4d70e4 100644 --- a/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsNotSolutionEditEnd.baseline +++ b/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsNotSolutionEditEnd.baseline @@ -358,6 +358,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 1 + }, + "ch": "c", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -383,6 +412,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 2 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -408,6 +466,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 3 + }, + "ch": "n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -433,6 +520,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 4 + }, + "ch": "s", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -458,6 +574,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 5 + }, + "ch": "t", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -483,6 +628,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 6 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -508,6 +682,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 7 + }, + "ch": "x", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -533,6 +736,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 8 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -558,6 +790,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 9 + }, + "ch": "=", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -583,6 +844,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 10 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -608,6 +898,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 11 + }, + "ch": "1", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -633,6 +952,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 12 + }, + "ch": "0", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/didChange", "params": { @@ -658,6 +1006,35 @@ Config:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///myproject/dependency/FnS.ts" + }, + "position": { + "line": 5, + "character": 13 + }, + "ch": ";", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/myproject/dependency/tsconfig.json] *modified* + /myproject/dependency/FnS.ts *modified* + [/myproject/main/tsconfig.json] + /myproject/decls/FnS.d.ts + /myproject/main/main.ts + [/myproject/tsconfig.json] + /myproject/dependency/FnS.ts + /myproject/main/main.ts + { "method": "textDocument/rename", "params": { @@ -673,8 +1050,8 @@ Config:: } Projects:: - [/myproject/dependency/tsconfig.json] *modified* - /myproject/dependency/FnS.ts *modified* + [/myproject/dependency/tsconfig.json] + /myproject/dependency/FnS.ts [/myproject/main/tsconfig.json] /myproject/decls/FnS.d.ts /myproject/main/main.ts diff --git a/testdata/baselines/reference/fourslash/state/findAllRefsDoesNotTryToSearchProjectAfterItsUpdateDoesNotIncludeTheFile.baseline b/testdata/baselines/reference/fourslash/state/findAllRefsDoesNotTryToSearchProjectAfterItsUpdateDoesNotIncludeTheFile.baseline index 1cf21205b1..3c87e26cb2 100644 --- a/testdata/baselines/reference/fourslash/state/findAllRefsDoesNotTryToSearchProjectAfterItsUpdateDoesNotIncludeTheFile.baseline +++ b/testdata/baselines/reference/fourslash/state/findAllRefsDoesNotTryToSearchProjectAfterItsUpdateDoesNotIncludeTheFile.baseline @@ -176,6 +176,40 @@ Config File Names:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///packages/babel-loader/src/index.ts" + }, + "position": { + "line": 0, + "character": 1 + }, + "ch": "/", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/packages/babel-loader/tsconfig.json] *modified* + /packages/babel-loader/src/index.ts *modified* + /packages/core/src/loading-indicator.ts *deleted* + /packages/core/src/index.ts *deleted* + [/packages/core/tsconfig.json] + /packages/core/src/loading-indicator.ts + /packages/core/src/index.ts +Open Files:: + [/packages/babel-loader/src/index.ts] + /packages/babel-loader/tsconfig.json (default) + [/packages/core/src/index.ts] *modified* + /packages/babel-loader/tsconfig.json *deleted* + /packages/core/tsconfig.json (default) + { "method": "textDocument/didChange", "params": { @@ -201,6 +235,32 @@ Config File Names:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///packages/babel-loader/src/index.ts" + }, + "position": { + "line": 0, + "character": 2 + }, + "ch": "/", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/packages/babel-loader/tsconfig.json] *modified* + /packages/babel-loader/src/index.ts *modified* + [/packages/core/tsconfig.json] + /packages/core/src/loading-indicator.ts + /packages/core/src/index.ts + { "method": "textDocument/didChange", "params": { @@ -226,6 +286,32 @@ Config File Names:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///packages/babel-loader/src/index.ts" + }, + "position": { + "line": 0, + "character": 3 + }, + "ch": " ", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/packages/babel-loader/tsconfig.json] *modified* + /packages/babel-loader/src/index.ts *modified* + [/packages/core/tsconfig.json] + /packages/core/src/loading-indicator.ts + /packages/core/src/index.ts + { "method": "textDocument/didChange", "params": { @@ -251,6 +337,32 @@ Config File Names:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///packages/babel-loader/src/index.ts" + }, + "position": { + "line": 0, + "character": 4 + }, + "ch": "c", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/packages/babel-loader/tsconfig.json] *modified* + /packages/babel-loader/src/index.ts *modified* + [/packages/core/tsconfig.json] + /packages/core/src/loading-indicator.ts + /packages/core/src/index.ts + { "method": "textDocument/didChange", "params": { @@ -276,6 +388,32 @@ Config File Names:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///packages/babel-loader/src/index.ts" + }, + "position": { + "line": 0, + "character": 5 + }, + "ch": "o", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/packages/babel-loader/tsconfig.json] *modified* + /packages/babel-loader/src/index.ts *modified* + [/packages/core/tsconfig.json] + /packages/core/src/loading-indicator.ts + /packages/core/src/index.ts + { "method": "textDocument/didChange", "params": { @@ -301,6 +439,32 @@ Config File Names:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///packages/babel-loader/src/index.ts" + }, + "position": { + "line": 0, + "character": 6 + }, + "ch": "m", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/packages/babel-loader/tsconfig.json] *modified* + /packages/babel-loader/src/index.ts *modified* + [/packages/core/tsconfig.json] + /packages/core/src/loading-indicator.ts + /packages/core/src/index.ts + { "method": "textDocument/didChange", "params": { @@ -326,6 +490,32 @@ Config File Names:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///packages/babel-loader/src/index.ts" + }, + "position": { + "line": 0, + "character": 7 + }, + "ch": "m", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/packages/babel-loader/tsconfig.json] *modified* + /packages/babel-loader/src/index.ts *modified* + [/packages/core/tsconfig.json] + /packages/core/src/loading-indicator.ts + /packages/core/src/index.ts + { "method": "textDocument/didChange", "params": { @@ -351,6 +541,32 @@ Config File Names:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///packages/babel-loader/src/index.ts" + }, + "position": { + "line": 0, + "character": 8 + }, + "ch": "e", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/packages/babel-loader/tsconfig.json] *modified* + /packages/babel-loader/src/index.ts *modified* + [/packages/core/tsconfig.json] + /packages/core/src/loading-indicator.ts + /packages/core/src/index.ts + { "method": "textDocument/didChange", "params": { @@ -376,6 +592,32 @@ Config File Names:: } } +{ + "method": "textDocument/onTypeFormatting", + "params": { + "textDocument": { + "uri": "file:///packages/babel-loader/src/index.ts" + }, + "position": { + "line": 0, + "character": 9 + }, + "ch": "n", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true + } + } +} + +Projects:: + [/packages/babel-loader/tsconfig.json] *modified* + /packages/babel-loader/src/index.ts *modified* + [/packages/core/tsconfig.json] + /packages/core/src/loading-indicator.ts + /packages/core/src/index.ts + { "method": "textDocument/didChange", "params": { @@ -402,35 +644,46 @@ Config File Names:: } { - "method": "textDocument/references", + "method": "textDocument/onTypeFormatting", "params": { "textDocument": { - "uri": "file:///packages/core/src/index.ts" + "uri": "file:///packages/babel-loader/src/index.ts" }, "position": { - "line": 3, - "character": 1 + "line": 0, + "character": 10 }, - "context": { - "includeDeclaration": true + "ch": "t", + "options": { + "tabSize": 4, + "insertSpaces": true, + "trimTrailingWhitespace": true } } } Projects:: [/packages/babel-loader/tsconfig.json] *modified* - /packages/babel-loader/src/index.ts *modified* - /packages/core/src/loading-indicator.ts *deleted* - /packages/core/src/index.ts *deleted* + /packages/babel-loader/src/index.ts *modified* [/packages/core/tsconfig.json] /packages/core/src/loading-indicator.ts /packages/core/src/index.ts -Open Files:: - [/packages/babel-loader/src/index.ts] - /packages/babel-loader/tsconfig.json (default) - [/packages/core/src/index.ts] *modified* - /packages/babel-loader/tsconfig.json *deleted* - /packages/core/tsconfig.json (default) + +{ + "method": "textDocument/references", + "params": { + "textDocument": { + "uri": "file:///packages/core/src/index.ts" + }, + "position": { + "line": 3, + "character": 1 + }, + "context": { + "includeDeclaration": true + } + } +} diff --git a/testdata/baselines/reference/submodule/compiler/arrowFunctionErrorSpan.errors.txt b/testdata/baselines/reference/submodule/compiler/arrowFunctionErrorSpan.errors.txt index 0cc9ee2b6a..fcac6d1f07 100644 --- a/testdata/baselines/reference/submodule/compiler/arrowFunctionErrorSpan.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/arrowFunctionErrorSpan.errors.txt @@ -32,7 +32,7 @@ arrowFunctionErrorSpan.ts(52,3): error TS2345: Argument of type '(_: any) => num // multiline, body f(() => { - ~~~~~~~ + ~~~~~~ !!! error TS2345: Argument of type '() => void' is not assignable to parameter of type '() => number'. !!! error TS2345: Type 'void' is not assignable to type 'number'. @@ -40,7 +40,7 @@ arrowFunctionErrorSpan.ts(52,3): error TS2345: Argument of type '(_: any) => num // multiline 2, body f(() => { - ~~~~~~~ + ~~~~~~ !!! error TS2345: Argument of type '() => void' is not assignable to parameter of type '() => number'. !!! error TS2345: Type 'void' is not assignable to type 'number'. @@ -85,7 +85,7 @@ arrowFunctionErrorSpan.ts(52,3): error TS2345: Argument of type '(_: any) => num // multi line with a comment 2 f(/* */() => { - ~~~~~~~~ + ~~~~~~~ !!! error TS2345: Argument of type '() => void' is not assignable to parameter of type '() => number'. !!! error TS2345: Type 'void' is not assignable to type 'number'. @@ -95,7 +95,7 @@ arrowFunctionErrorSpan.ts(52,3): error TS2345: Argument of type '(_: any) => num f( // comment 1 // comment 2 () => - ~~~~~ + ~~~~ !!! error TS2345: Argument of type '() => void' is not assignable to parameter of type '() => number'. !!! error TS2345: Type 'void' is not assignable to type 'number'. // comment 3 diff --git a/testdata/baselines/reference/submodule/compiler/arrowFunctionErrorSpan.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/arrowFunctionErrorSpan.errors.txt.diff new file mode 100644 index 0000000000..b0271a1ef3 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/arrowFunctionErrorSpan.errors.txt.diff @@ -0,0 +1,38 @@ +--- old.arrowFunctionErrorSpan.errors.txt ++++ new.arrowFunctionErrorSpan.errors.txt +@@= skipped -31, +31 lines =@@ + + // multiline, body + f(() => { +- ~~~~~~~ ++ ~~~~~~ + !!! error TS2345: Argument of type '() => void' is not assignable to parameter of type '() => number'. + !!! error TS2345: Type 'void' is not assignable to type 'number'. + +@@= skipped -8, +8 lines =@@ + + // multiline 2, body + f(() => { +- ~~~~~~~ ++ ~~~~~~ + !!! error TS2345: Argument of type '() => void' is not assignable to parameter of type '() => number'. + !!! error TS2345: Type 'void' is not assignable to type 'number'. + +@@= skipped -45, +45 lines =@@ + // multi line with a comment 2 + f(/* + */() => { +- ~~~~~~~~ ++ ~~~~~~~ + !!! error TS2345: Argument of type '() => void' is not assignable to parameter of type '() => number'. + !!! error TS2345: Type 'void' is not assignable to type 'number'. + +@@= skipped -10, +10 lines =@@ + f( // comment 1 + // comment 2 + () => +- ~~~~~ ++ ~~~~ + !!! error TS2345: Argument of type '() => void' is not assignable to parameter of type '() => number'. + !!! error TS2345: Type 'void' is not assignable to type 'number'. + // comment 3 \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/asyncFunctionNoReturnType.errors.txt b/testdata/baselines/reference/submodule/compiler/asyncFunctionNoReturnType.errors.txt index 104884d4da..4a8c311092 100644 --- a/testdata/baselines/reference/submodule/compiler/asyncFunctionNoReturnType.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/asyncFunctionNoReturnType.errors.txt @@ -5,7 +5,7 @@ asyncFunctionNoReturnType.ts(1,1): error TS2705: An async function or method in !!! error TS2468: Cannot find global value 'Promise'. ==== asyncFunctionNoReturnType.ts (1 errors) ==== async () => { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~~ !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. if (window) return; diff --git a/testdata/baselines/reference/submodule/compiler/asyncFunctionNoReturnType.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/asyncFunctionNoReturnType.errors.txt.diff new file mode 100644 index 0000000000..8fef185c66 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/asyncFunctionNoReturnType.errors.txt.diff @@ -0,0 +1,11 @@ +--- old.asyncFunctionNoReturnType.errors.txt ++++ new.asyncFunctionNoReturnType.errors.txt +@@= skipped -4, +4 lines =@@ + !!! error TS2468: Cannot find global value 'Promise'. + ==== asyncFunctionNoReturnType.ts (1 errors) ==== + async () => { +- ~~~~~~~~~~~~~ ++ ~~~~~~~~~~~~ + !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. + if (window) + return; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/contextualTupleTypeParameterReadonly.errors.txt b/testdata/baselines/reference/submodule/compiler/contextualTupleTypeParameterReadonly.errors.txt index 5842133170..e05cf81e23 100644 --- a/testdata/baselines/reference/submodule/compiler/contextualTupleTypeParameterReadonly.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/contextualTupleTypeParameterReadonly.errors.txt @@ -15,7 +15,7 @@ contextualTupleTypeParameterReadonly.ts(10,8): error TS2345: Argument of type '( const eacher = each(cases); eacher((a, b) => { - ~~~~~~~~~~~ + ~~~~~~~~~~ !!! error TS2345: Argument of type '(a: 1 | 2, b: "1" | "2") => void' is not assignable to parameter of type '(...args: readonly [1, "1"] | readonly [2, "2"]) => any'. !!! error TS2345: Types of parameters 'a' and 'args' are incompatible. !!! error TS2345: Type 'readonly [1, "1"] | readonly [2, "2"]' is not assignable to type '[a: 1 | 2, b: "1" | "2"]'. diff --git a/testdata/baselines/reference/submodule/compiler/contextualTupleTypeParameterReadonly.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/contextualTupleTypeParameterReadonly.errors.txt.diff new file mode 100644 index 0000000000..276384b085 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/contextualTupleTypeParameterReadonly.errors.txt.diff @@ -0,0 +1,11 @@ +--- old.contextualTupleTypeParameterReadonly.errors.txt ++++ new.contextualTupleTypeParameterReadonly.errors.txt +@@= skipped -14, +14 lines =@@ + const eacher = each(cases); + + eacher((a, b) => { +- ~~~~~~~~~~~ ++ ~~~~~~~~~~ + !!! error TS2345: Argument of type '(a: 1 | 2, b: "1" | "2") => void' is not assignable to parameter of type '(...args: readonly [1, "1"] | readonly [2, "2"]) => any'. + !!! error TS2345: Types of parameters 'a' and 'args' are incompatible. + !!! error TS2345: Type 'readonly [1, "1"] | readonly [2, "2"]' is not assignable to type '[a: 1 | 2, b: "1" | "2"]'. \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/noImplicitReturnsExclusions.errors.txt b/testdata/baselines/reference/submodule/compiler/noImplicitReturnsExclusions.errors.txt index 179d92dce8..73067a88e2 100644 --- a/testdata/baselines/reference/submodule/compiler/noImplicitReturnsExclusions.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/noImplicitReturnsExclusions.errors.txt @@ -108,7 +108,7 @@ noImplicitReturnsExclusions.ts(88,53): error TS7030: Not all code paths return a ): void; registerCommand("_references-view.showHistoryItem", async (item) => { // Error, contextual return type of Promise - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS7030: Not all code paths return a value. if (item instanceof HistoryItem) { return executeCommand("vscode.open", item.input.location.uri); diff --git a/testdata/baselines/reference/submodule/compiler/noImplicitReturnsExclusions.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/noImplicitReturnsExclusions.errors.txt.diff new file mode 100644 index 0000000000..4cefe07ee0 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/noImplicitReturnsExclusions.errors.txt.diff @@ -0,0 +1,11 @@ +--- old.noImplicitReturnsExclusions.errors.txt ++++ new.noImplicitReturnsExclusions.errors.txt +@@= skipped -107, +107 lines =@@ + ): void; + + registerCommand("_references-view.showHistoryItem", async (item) => { // Error, contextual return type of Promise +- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ++ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + !!! error TS7030: Not all code paths return a value. + if (item instanceof HistoryItem) { + return executeCommand("vscode.open", item.input.location.uri); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/overloadresolutionWithConstraintCheckingDeferred.errors.txt b/testdata/baselines/reference/submodule/compiler/overloadresolutionWithConstraintCheckingDeferred.errors.txt index bc0e42a66f..007e59db26 100644 --- a/testdata/baselines/reference/submodule/compiler/overloadresolutionWithConstraintCheckingDeferred.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/overloadresolutionWithConstraintCheckingDeferred.errors.txt @@ -59,7 +59,7 @@ overloadresolutionWithConstraintCheckingDeferred.ts(19,14): error TS2741: Proper !!! related TS2728 overloadresolutionWithConstraintCheckingDeferred.ts:1:15: 'x' is declared here. var result3: string = foo(x => { // x has type D - ~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2769: No overload matches this call. !!! error TS2769: The last overload gave the following error. !!! error TS2769: Argument of type '(x: D) => G' is not assignable to parameter of type '(x: B) => any'. diff --git a/testdata/baselines/reference/submodule/compiler/overloadresolutionWithConstraintCheckingDeferred.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/overloadresolutionWithConstraintCheckingDeferred.errors.txt.diff index d51c735306..82b751f386 100644 --- a/testdata/baselines/reference/submodule/compiler/overloadresolutionWithConstraintCheckingDeferred.errors.txt.diff +++ b/testdata/baselines/reference/submodule/compiler/overloadresolutionWithConstraintCheckingDeferred.errors.txt.diff @@ -108,7 +108,8 @@ !!! related TS2728 overloadresolutionWithConstraintCheckingDeferred.ts:1:15: 'x' is declared here. var result3: string = foo(x => { // x has type D - ~~~~~~~~~~~~~~~~~~~~~~ +- ~~~~~~~~~~~~~~~~~~~~~~ ++ ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2769: No overload matches this call. -!!! error TS2769: Overload 1 of 3, '(arg: (x: D) => number): string', gave the following error. -!!! error TS2769: Argument of type '(x: D) => G' is not assignable to parameter of type '(x: D) => number'. diff --git a/testdata/baselines/reference/submodule/compiler/recursiveTypeRelations.errors.txt b/testdata/baselines/reference/submodule/compiler/recursiveTypeRelations.errors.txt index 52bf8e1c36..4e6b4d92b4 100644 --- a/testdata/baselines/reference/submodule/compiler/recursiveTypeRelations.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/recursiveTypeRelations.errors.txt @@ -38,7 +38,7 @@ recursiveTypeRelations.ts(27,61): error TS2552: Cannot find name 'ClassNameObjec return Object.keys(arg).reduce((obj: ClassNameObject, key: keyof S) => { ~~~~~~~~~~~~~~~ !!! error TS2552: Cannot find name 'ClassNameObject'. Did you mean 'ClassNameObjectMap'? - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(obj: ClassNameObject, key: keyof S) => ClassNameObject' is not assignable to parameter of type '(previousValue: ClassNameObject, currentValue: string, currentIndex: number, array: string[]) => ClassNameObject'. !!! error TS2345: Types of parameters 'key' and 'currentValue' are incompatible. !!! error TS2345: Type 'string' is not assignable to type 'keyof S'. diff --git a/testdata/baselines/reference/submodule/compiler/recursiveTypeRelations.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/recursiveTypeRelations.errors.txt.diff new file mode 100644 index 0000000000..008ab674d4 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/recursiveTypeRelations.errors.txt.diff @@ -0,0 +1,11 @@ +--- old.recursiveTypeRelations.errors.txt ++++ new.recursiveTypeRelations.errors.txt +@@= skipped -37, +37 lines =@@ + return Object.keys(arg).reduce((obj: ClassNameObject, key: keyof S) => { + ~~~~~~~~~~~~~~~ + !!! error TS2552: Cannot find name 'ClassNameObject'. Did you mean 'ClassNameObjectMap'? +- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ++ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + !!! error TS2345: Argument of type '(obj: ClassNameObject, key: keyof S) => ClassNameObject' is not assignable to parameter of type '(previousValue: ClassNameObject, currentValue: string, currentIndex: number, array: string[]) => ClassNameObject'. + !!! error TS2345: Types of parameters 'key' and 'currentValue' are incompatible. + !!! error TS2345: Type 'string' is not assignable to type 'keyof S'. \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/undeclaredModuleError.errors.txt b/testdata/baselines/reference/submodule/compiler/undeclaredModuleError.errors.txt index 2960755565..afac4f0d8a 100644 --- a/testdata/baselines/reference/submodule/compiler/undeclaredModuleError.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/undeclaredModuleError.errors.txt @@ -15,7 +15,7 @@ undeclaredModuleError.ts(11,41): error TS2304: Cannot find name 'IDoNotExist'. function instrumentFile(covFileDir: string, covFileName: string, originalFilePath: string) { fs.readFile(originalFilePath, () => { readdir(covFileDir, () => { - ~~~~~~~ + ~~~~~~ !!! error TS2345: Argument of type '() => void' is not assignable to parameter of type '(stat: fs.Stats, name: string) => boolean'. !!! error TS2345: Type 'void' is not assignable to type 'boolean'. } , (error: Error, files: {}[]) => { diff --git a/testdata/baselines/reference/submodule/compiler/undeclaredModuleError.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/undeclaredModuleError.errors.txt.diff new file mode 100644 index 0000000000..62ecfc558e --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/undeclaredModuleError.errors.txt.diff @@ -0,0 +1,11 @@ +--- old.undeclaredModuleError.errors.txt ++++ new.undeclaredModuleError.errors.txt +@@= skipped -14, +14 lines =@@ + function instrumentFile(covFileDir: string, covFileName: string, originalFilePath: string) { + fs.readFile(originalFilePath, () => { + readdir(covFileDir, () => { +- ~~~~~~~ ++ ~~~~~~ + !!! error TS2345: Argument of type '() => void' is not assignable to parameter of type '(stat: fs.Stats, name: string) => boolean'. + !!! error TS2345: Type 'void' is not assignable to type 'boolean'. + } , (error: Error, files: {}[]) => { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/importCallExpressionNoModuleKindSpecified.errors.txt b/testdata/baselines/reference/submodule/conformance/importCallExpressionNoModuleKindSpecified.errors.txt index 1437429794..d50f005e0a 100644 --- a/testdata/baselines/reference/submodule/conformance/importCallExpressionNoModuleKindSpecified.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/importCallExpressionNoModuleKindSpecified.errors.txt @@ -29,7 +29,7 @@ error TS2468: Cannot find global value 'Promise'. this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. console.log(err); let one = await import("./1"); diff --git a/testdata/baselines/reference/submodule/conformance/importCallExpressionNoModuleKindSpecified.errors.txt.diff b/testdata/baselines/reference/submodule/conformance/importCallExpressionNoModuleKindSpecified.errors.txt.diff new file mode 100644 index 0000000000..9a71ad76aa --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/importCallExpressionNoModuleKindSpecified.errors.txt.diff @@ -0,0 +1,11 @@ +--- old.importCallExpressionNoModuleKindSpecified.errors.txt ++++ new.importCallExpressionNoModuleKindSpecified.errors.txt +@@= skipped -28, +28 lines =@@ + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { +- ~~~~~~~~~~~~~~ ++ ~~~~~~~~~~~~~ + !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. + console.log(err); + let one = await import("./1"); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=es5).errors.txt b/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=es5).errors.txt index e86672a229..c2e7432f6b 100644 --- a/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=es5).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=es5).errors.txt @@ -27,7 +27,7 @@ scriptLookingFile01.ts(3,22): error TS17012: 'import' is not a valid meta-proper ==== example.ts (4 errors) ==== // Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example (async () => { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~~ !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString()); ~~~~~~~~~~~ diff --git a/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=es5).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=es5).errors.txt.diff new file mode 100644 index 0000000000..2b81a2ec04 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=es5).errors.txt.diff @@ -0,0 +1,11 @@ +--- old.importMeta(module=commonjs,target=es5).errors.txt ++++ new.importMeta(module=commonjs,target=es5).errors.txt +@@= skipped -26, +26 lines =@@ + ==== example.ts (4 errors) ==== + // Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example + (async () => { +- ~~~~~~~~~~~~~ ++ ~~~~~~~~~~~~ + !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. + const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString()); + ~~~~~~~~~~~ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=esnext).errors.txt b/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=esnext).errors.txt index e86672a229..c2e7432f6b 100644 --- a/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=esnext).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=esnext).errors.txt @@ -27,7 +27,7 @@ scriptLookingFile01.ts(3,22): error TS17012: 'import' is not a valid meta-proper ==== example.ts (4 errors) ==== // Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example (async () => { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~~ !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString()); ~~~~~~~~~~~ diff --git a/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=esnext).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=esnext).errors.txt.diff new file mode 100644 index 0000000000..af10cd02d5 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/importMeta(module=commonjs,target=esnext).errors.txt.diff @@ -0,0 +1,11 @@ +--- old.importMeta(module=commonjs,target=esnext).errors.txt ++++ new.importMeta(module=commonjs,target=esnext).errors.txt +@@= skipped -26, +26 lines =@@ + ==== example.ts (4 errors) ==== + // Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example + (async () => { +- ~~~~~~~~~~~~~ ++ ~~~~~~~~~~~~ + !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. + const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString()); + ~~~~~~~~~~~ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=es5).errors.txt b/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=es5).errors.txt index 8c43f299b5..2519f95c43 100644 --- a/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=es5).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=es5).errors.txt @@ -14,7 +14,7 @@ scriptLookingFile01.ts(3,22): error TS17012: 'import' is not a valid meta-proper ==== example.ts (2 errors) ==== // Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example (async () => { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~~ !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString()); const blob = await response.blob(); diff --git a/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=es5).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=es5).errors.txt.diff new file mode 100644 index 0000000000..fdb0bb919e --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=es5).errors.txt.diff @@ -0,0 +1,11 @@ +--- old.importMeta(module=es2020,target=es5).errors.txt ++++ new.importMeta(module=es2020,target=es5).errors.txt +@@= skipped -13, +13 lines =@@ + ==== example.ts (2 errors) ==== + // Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example + (async () => { +- ~~~~~~~~~~~~~ ++ ~~~~~~~~~~~~ + !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. + const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString()); + const blob = await response.blob(); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=esnext).errors.txt b/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=esnext).errors.txt index 8c43f299b5..2519f95c43 100644 --- a/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=esnext).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=esnext).errors.txt @@ -14,7 +14,7 @@ scriptLookingFile01.ts(3,22): error TS17012: 'import' is not a valid meta-proper ==== example.ts (2 errors) ==== // Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example (async () => { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~~ !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString()); const blob = await response.blob(); diff --git a/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=esnext).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=esnext).errors.txt.diff new file mode 100644 index 0000000000..ee20ab05d8 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/importMeta(module=es2020,target=esnext).errors.txt.diff @@ -0,0 +1,11 @@ +--- old.importMeta(module=es2020,target=esnext).errors.txt ++++ new.importMeta(module=es2020,target=esnext).errors.txt +@@= skipped -13, +13 lines =@@ + ==== example.ts (2 errors) ==== + // Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example + (async () => { +- ~~~~~~~~~~~~~ ++ ~~~~~~~~~~~~ + !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. + const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString()); + const blob = await response.blob(); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=es5).errors.txt b/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=es5).errors.txt index 8c43f299b5..2519f95c43 100644 --- a/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=es5).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=es5).errors.txt @@ -14,7 +14,7 @@ scriptLookingFile01.ts(3,22): error TS17012: 'import' is not a valid meta-proper ==== example.ts (2 errors) ==== // Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example (async () => { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~~ !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString()); const blob = await response.blob(); diff --git a/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=es5).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=es5).errors.txt.diff new file mode 100644 index 0000000000..effb69098a --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=es5).errors.txt.diff @@ -0,0 +1,11 @@ +--- old.importMeta(module=esnext,target=es5).errors.txt ++++ new.importMeta(module=esnext,target=es5).errors.txt +@@= skipped -13, +13 lines =@@ + ==== example.ts (2 errors) ==== + // Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example + (async () => { +- ~~~~~~~~~~~~~ ++ ~~~~~~~~~~~~ + !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. + const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString()); + const blob = await response.blob(); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=esnext).errors.txt b/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=esnext).errors.txt index 8c43f299b5..2519f95c43 100644 --- a/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=esnext).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=esnext).errors.txt @@ -14,7 +14,7 @@ scriptLookingFile01.ts(3,22): error TS17012: 'import' is not a valid meta-proper ==== example.ts (2 errors) ==== // Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example (async () => { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~~ !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString()); const blob = await response.blob(); diff --git a/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=esnext).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=esnext).errors.txt.diff new file mode 100644 index 0000000000..31356afc1b --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/importMeta(module=esnext,target=esnext).errors.txt.diff @@ -0,0 +1,11 @@ +--- old.importMeta(module=esnext,target=esnext).errors.txt ++++ new.importMeta(module=esnext,target=esnext).errors.txt +@@= skipped -13, +13 lines =@@ + ==== example.ts (2 errors) ==== + // Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example + (async () => { +- ~~~~~~~~~~~~~ ++ ~~~~~~~~~~~~ + !!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. + const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString()); + const blob = await response.blob(); \ No newline at end of file From c1050230ef0f74b0dc016c1b210ed8d5978d04e6 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Fri, 12 Dec 2025 13:50:07 -0800 Subject: [PATCH 4/5] updatefailing --- internal/fourslash/_scripts/crashingTests.txt | 2 ++ internal/fourslash/_scripts/failingTests.txt | 36 +------------------ .../tests/gen/asOperatorFormatting_test.go | 2 +- .../tests/gen/autoFormattingOnPasting_test.go | 9 ----- .../tests/gen/autoImportProvider1_test.go | 2 +- .../tests/gen/autoImportProvider2_test.go | 2 +- .../tests/gen/autoImportProvider7_test.go | 2 +- .../tests/gen/autoImportProvider8_test.go | 2 +- .../gen/chainedFatArrowFormatting_test.go | 9 ----- .../tests/gen/commentsBlocks_test.go | 2 +- ..._addToNamedWithDifferentCacheValue_test.go | 2 +- ...nsImport_jsModuleExportsAssignment_test.go | 2 +- ...onsOfObjectsInAListAfterFormatting_test.go | 2 +- .../gen/constructorBraceFormatting_test.go | 9 ----- .../gen/forceIndentAfterNewLineInsert_test.go | 2 +- internal/fourslash/tests/gen/format01_test.go | 2 +- .../gen/formatAfterMultilineComment_test.go | 2 +- .../gen/formatAfterObjectLiteral_test.go | 2 +- .../gen/formatAfterPasteInString_test.go | 2 +- .../tests/gen/formatAfterWhitespace_test.go | 9 ----- .../tests/gen/formatAnyTypeLiteral_test.go | 9 ----- .../gen/formatArrayLiteralExpression_test.go | 2 +- ...rrayOrObjectLiteralsInVariableList_test.go | 2 +- .../tests/gen/formatAsyncClassMethod1_test.go | 2 +- .../tests/gen/formatAsyncClassMethod2_test.go | 2 +- .../gen/formatAsyncComputedMethod_test.go | 2 +- .../tests/gen/formatAsyncKeyword_test.go | 2 +- .../gen/formatBracketInSwitchCase_test.go | 2 +- .../tests/gen/formatColonAndQMark_test.go | 2 +- .../tests/gen/formatComments_test.go | 2 +- .../gen/formatConflictDiff3Marker1_test.go | 2 +- .../tests/gen/formatConflictMarker1_test.go | 2 +- .../gen/formatControlFlowConstructs_test.go | 2 +- .../tests/gen/formatDebuggerStatement_test.go | 2 +- ...DocumentPreserveTrailingWhitespace_test.go | 2 +- .../tests/gen/formatDocumentWithJSDoc_test.go | 2 +- .../gen/formatDocumentWithTrivia_test.go | 2 +- .../tests/gen/formatDotAfterNumber_test.go | 2 +- .../tests/gen/formatEmptyBlock_test.go | 9 ----- .../tests/gen/formatEmptyParamList_test.go | 9 ----- .../tests/gen/formatExportAssignment_test.go | 2 +- .../tests/gen/formatIfTryCatchBlocks_test.go | 2 +- .../gen/formatIfWithEmptyCondition_test.go | 2 +- .../tests/gen/formatImplicitModule_test.go | 2 +- .../tests/gen/formatImportDeclaration_test.go | 2 +- .../tests/gen/formatInTryCatchFinally_test.go | 9 ----- .../tests/gen/formatInTsxFiles_test.go | 2 +- ...eAfterCloseBraceBeforeCloseBracket_test.go | 2 +- .../formatJsxWithKeywordInIdentifier_test.go | 2 +- ...teralTypeInUnionOrIntersectionType_test.go | 2 +- .../tests/gen/formatMultilineComment_test.go | 2 +- .../formatMultilineTypesWithMapped_test.go | 2 +- .../formatMultipleFunctionArguments_test.go | 2 +- ...NestedClassWithOpenBraceOnNewLines_test.go | 2 +- ...tNoSpaceAfterTemplateHeadAndMiddle_test.go | 2 +- .../formatNoSpaceBeforeCloseBrace1_test.go | 2 +- .../formatNoSpaceBeforeCloseBrace2_test.go | 2 +- .../formatNoSpaceBeforeCloseBrace3_test.go | 2 +- .../formatNoSpaceBeforeCloseBrace4_test.go | 2 +- .../formatNoSpaceBeforeCloseBrace5_test.go | 2 +- .../formatNoSpaceBeforeCloseBrace6_test.go | 2 +- .../gen/formatNoSpaceBeforeCloseBrace_test.go | 2 +- ...tweenClosingParenAndTemplateString_test.go | 2 +- ...attern_restElementWithPropertyName_test.go | 2 +- .../gen/formatObjectBindingPattern_test.go | 2 +- .../formatOnEnterFunctionDeclaration_test.go | 9 ----- .../tests/gen/formatOnEnterInComment_test.go | 9 ----- .../formatOnEnterOpenBraceAddNewLine_test.go | 2 +- ...ormatOnOpenCurlyBraceRemoveNewLine_test.go | 2 +- .../gen/formatOnSemiColonAfterBreak_test.go | 9 ----- .../tests/gen/formatParameter_test.go | 2 +- .../formatRemoveNewLineAfterOpenBrace_test.go | 2 +- ...veSpaceBetweenDotDotDotAndTypeName_test.go | 2 +- .../gen/formatSatisfiesExpression_test.go | 2 +- .../formatSpaceAfterImplementsExtends_test.go | 2 +- ...matSpaceAfterTemplateHeadAndMiddle_test.go | 2 +- ...tSpaceBetweenFunctionAndArrayIndex_test.go | 2 +- .../gen/formatTSXWithInlineComment_test.go | 2 +- .../tests/gen/formatTryCatch_test.go | 2 +- .../tests/gen/formatTryFinally_test.go | 2 +- .../gen/formatTsxClosingAfterJsxText_test.go | 2 +- .../formatTsxMultilineAttributeString_test.go | 2 +- .../fourslash/tests/gen/formatTsx_test.go | 2 +- .../tests/gen/formatTypeAnnotation1_test.go | 2 +- .../tests/gen/formatTypeAnnotation2_test.go | 2 +- .../gen/formatTypeArgumentOnNewLine_test.go | 2 +- .../tests/gen/formatTypeParameters_test.go | 2 +- .../gen/formatVariableDeclarationList_test.go | 2 +- .../tests/gen/formatWithStatement_test.go | 2 +- .../fourslash/tests/gen/formatonkey01_test.go | 9 ----- .../formattingAfterChainedFatArrow_test.go | 2 +- ...ormattingAfterMultiLineIfCondition_test.go | 9 ----- .../formattingAfterMultiLineString_test.go | 9 ----- .../tests/gen/formattingArrayLiteral_test.go | 2 +- .../tests/gen/formattingAwait_test.go | 2 +- .../gen/formattingBlockInCaseClauses_test.go | 9 ----- .../gen/formattingChainingMethods_test.go | 2 +- .../tests/gen/formattingComma_test.go | 2 +- .../formattingCommentsBeforeErrors_test.go | 9 ----- .../gen/formattingConditionalOperator_test.go | 2 +- .../gen/formattingConditionalTypes_test.go | 2 +- .../tests/gen/formattingCrash_test.go | 2 +- .../tests/gen/formattingDecorators_test.go | 2 +- .../gen/formattingDoubleLessThan_test.go | 2 +- .../gen/formattingElseInsideAFunction_test.go | 9 ----- ...tingEqualsBeforeBracketInTypeAlias_test.go | 9 ----- ...formattingExpressionsInIfCondition_test.go | 9 ----- .../gen/formattingFatArrowFunctions_test.go | 2 +- .../tests/gen/formattingForIn_test.go | 2 +- .../gen/formattingForLoopSemicolons_test.go | 2 +- .../tests/gen/formattingForOfKeyword_test.go | 2 +- .../gen/formattingGlobalAugmentation1_test.go | 2 +- .../gen/formattingGlobalAugmentation2_test.go | 2 +- .../tests/gen/formattingHexLiteral_test.go | 2 +- .../tests/gen/formattingIfInElseBlock_test.go | 9 ----- .../gen/formattingIllegalImportClause_test.go | 2 +- .../tests/gen/formattingInComment_test.go | 12 ------- .../gen/formattingInDestructuring1_test.go | 2 +- .../gen/formattingInDestructuring2_test.go | 2 +- .../gen/formattingInDestructuring3_test.go | 2 +- .../gen/formattingInDestructuring4_test.go | 2 +- .../gen/formattingInDestructuring5_test.go | 2 +- .../gen/formattingInExpressionsInTsx_test.go | 9 ----- .../gen/formattingInMultilineComments_test.go | 9 ----- .../tests/gen/formattingJsxTexts1_test.go | 2 +- .../tests/gen/formattingJsxTexts2_test.go | 2 +- .../tests/gen/formattingJsxTexts3_test.go | 2 +- .../tests/gen/formattingJsxTexts4_test.go | 2 +- .../gen/formattingKeywordAsIdentifier_test.go | 9 ----- .../tests/gen/formattingMappedType_test.go | 2 +- ...rmattingMultilineCommentsWithTabs1_test.go | 2 +- ...ormattingMultilineTemplateLiterals_test.go | 2 +- .../tests/gen/formattingNestedScopes_test.go | 2 +- ...formattingNonNullAssertionOperator_test.go | 2 +- ...tLiteralOpenCurlyNewlineAssignment_test.go | 2 +- ...bjectLiteralOpenCurlyNewlineTyping_test.go | 2 +- ...ttingObjectLiteralOpenCurlyNewline_test.go | 2 +- ...ngObjectLiteralOpenCurlySingleLine_test.go | 2 +- .../tests/gen/formattingObjectLiteral_test.go | 2 +- .../gen/formattingOfChainedLambda_test.go | 9 ----- .../gen/formattingOfExportDefault_test.go | 2 +- ...rmattingOfMultilineBlockConstructs_test.go | 2 +- ...hainedCallbacksAndPropertyAccesses_test.go | 2 +- .../tests/gen/formattingOnClasses_test.go | 2 +- .../tests/gen/formattingOnCloseBrace_test.go | 9 ----- .../gen/formattingOnClosingBracket_test.go | 2 +- .../gen/formattingOnCommaOperator_test.go | 2 +- .../formattingOnConstructorSignature_test.go | 2 +- .../formattingOnDoWhileNoSemicolon_test.go | 17 --------- .../formattingOnDocumentReadyFunction_test.go | 2 +- .../formattingOnEmptyInterfaceLiteral_test.go | 2 +- .../gen/formattingOnEnterInComments_test.go | 9 ----- .../gen/formattingOnEnterInStrings_test.go | 9 ----- .../tests/gen/formattingOnEnter_test.go | 9 ----- .../tests/gen/formattingOnInterfaces_test.go | 2 +- .../gen/formattingOnInvalidCodes_test.go | 2 +- .../gen/formattingOnModuleIndentation_test.go | 2 +- .../formattingOnNestedDoWhileByEnter_test.go | 21 ----------- .../gen/formattingOnObjectLiteral_test.go | 2 +- .../formattingOnOpenBraceOfFunctions_test.go | 2 +- .../tests/gen/formattingOnSemiColon_test.go | 9 ----- .../gen/formattingOnSingleLineBlocks_test.go | 2 +- ...mattingOnStatementsWithNoSemicolon_test.go | 2 +- .../formattingOnTabAfterCloseCurly_test.go | 2 +- .../tests/gen/formattingOnVariety_test.go | 2 +- .../tests/gen/formattingQMark_test.go | 2 +- .../tests/gen/formattingReadonly_test.go | 2 +- .../tests/gen/formattingRegexes_test.go | 9 ----- .../formattingReplaceTabsWithSpaces_test.go | 2 +- ...tingSingleLineWithNewLineOptionSet_test.go | 2 +- .../tests/gen/formattingSkippedTokens_test.go | 2 +- ...tingSpaceAfterCommaBeforeOpenParen_test.go | 12 ------- .../formattingSpaceBeforeCloseParen_test.go | 2 +- ...formattingSpaceBeforeFunctionParen_test.go | 2 +- ...attingSpaceBetweenOptionalChaining_test.go | 2 +- .../gen/formattingSpaceBetweenParent_test.go | 2 +- .../formattingSpacesAfterConstructor_test.go | 2 +- .../formattingTemplatesWithNewline_test.go | 9 ----- .../tests/gen/formattingTemplates_test.go | 12 ------- .../tests/gen/formattingTypeInfer_test.go | 2 +- .../tests/gen/formattingVoid_test.go | 2 +- .../formattingWithMultilineComments_test.go | 9 ----- ...mattingofSingleLineBlockConstructs_test.go | 2 +- .../tests/gen/functionFormatting_test.go | 2 +- .../tests/gen/functionIndentation_test.go | 2 +- .../tests/gen/functionTypeFormatting_test.go | 9 ----- .../functionTypePredicateFormatting_test.go | 2 +- .../generatorDeclarationFormatting_test.go | 2 +- .../gen/genericsFormattingMultiline_test.go | 2 +- .../tests/gen/genericsFormatting_test.go | 2 +- ...tNameCodeFix_externalNonRelateive2_test.go | 9 ++--- ...rtNameCodeFix_externalNonRelative1_test.go | 7 ++-- .../tests/gen/importTypeFormatting_test.go | 2 +- .../indentAfterFunctionClosingBraces_test.go | 9 ----- .../tests/gen/indentationInJsx3_test.go | 2 +- .../multilineCommentBeforeOpenBrace_test.go | 2 +- .../gen/optionalPropertyFormatting_test.go | 2 +- internal/fourslash/tests/gen/paste_test.go | 9 ----- ...micolonFormattingAfterArrayLiteral_test.go | 9 ----- .../semicolonFormattingInsideAComment_test.go | 9 ----- ...olonFormattingInsideAStringLiteral_test.go | 9 ----- ...emicolonFormattingNestedStatements_test.go | 13 ------- .../tests/gen/semicolonFormatting_test.go | 9 ----- .../singleLineTypeLiteralFormatting_test.go | 9 ----- .../tests/gen/smartIndentNamedImport_test.go | 2 +- .../tests/gen/spaceAfterConstructor_test.go | 9 ----- .../tests/gen/spaceAfterReturn_test.go | 2 +- .../gen/spaceAfterStatementConditions_test.go | 2 +- ...spaceBeforeAndAfterBinaryOperators_test.go | 2 +- ...ingAfterNewlineInsertedBeforeWhile_test.go | 9 ----- .../gen/typeAssertionsFormatting_test.go | 2 +- ...unclosedStringLiteralAutoformating_test.go | 9 ----- ...iteSpaceBeforeReturnTypeFormatting_test.go | 9 ----- .../tests/gen/whiteSpaceTrimming2_test.go | 9 ----- .../tests/gen/whiteSpaceTrimming3_test.go | 9 ----- .../tests/gen/whiteSpaceTrimming4_test.go | 9 ----- .../tests/gen/whiteSpaceTrimming_test.go | 9 ----- internal/lsp/server.go | 9 ----- internal/project/snapshot.go | 1 - 219 files changed, 171 insertions(+), 730 deletions(-) diff --git a/internal/fourslash/_scripts/crashingTests.txt b/internal/fourslash/_scripts/crashingTests.txt index c8ceb4d30c..14a9600659 100644 --- a/internal/fourslash/_scripts/crashingTests.txt +++ b/internal/fourslash/_scripts/crashingTests.txt @@ -3,6 +3,8 @@ TestCompletionsImport_require_addToExisting TestCompletionsUniqueSymbol_import TestFindReferencesBindingPatternInJsdocNoCrash1 TestFindReferencesBindingPatternInJsdocNoCrash2 +TestFormatDocumentWithTrivia +TestFormattingJsxTexts4 TestGetOccurrencesIfElseBroken TestImportNameCodeFix_importType8 TestJsdocLink2 diff --git a/internal/fourslash/_scripts/failingTests.txt b/internal/fourslash/_scripts/failingTests.txt index 0dc5cec241..116f00ef8a 100644 --- a/internal/fourslash/_scripts/failingTests.txt +++ b/internal/fourslash/_scripts/failingTests.txt @@ -39,8 +39,6 @@ TestAutoImportProvider_wildcardExports2 TestAutoImportProvider_wildcardExports3 TestAutoImportProvider1 TestAutoImportProvider4 -TestAutoImportProvider7 -TestAutoImportProvider8 TestAutoImportProvider9 TestAutoImportSortCaseSensitivity1 TestAutoImportTypeImport1 @@ -100,7 +98,6 @@ TestCompletionForStringLiteralNonrelativeImport2 TestCompletionForStringLiteralNonrelativeImport3 TestCompletionForStringLiteralNonrelativeImport4 TestCompletionForStringLiteralNonrelativeImport8 -TestCompletionForStringLiteralNonrelativeImport9 TestCompletionForStringLiteralNonrelativeImportTypings1 TestCompletionForStringLiteralNonrelativeImportTypings2 TestCompletionForStringLiteralNonrelativeImportTypings3 @@ -244,7 +241,6 @@ TestCompletionsWithDeprecatedTag10 TestCompletionWithConditionalOperatorMissingColon TestConstEnumQuickInfoAndCompletionList TestConstQuickInfoAndCompletionList -TestConstructorBraceFormatting TestContextuallyTypedFunctionExpressionGeneric1 TestContextualTypingOfGenericCallSignatures2 TestCrossFileQuickInfoExportedTypeDoesNotUseImportType @@ -336,27 +332,6 @@ TestFormatVariableDeclarationList TestFormatWithStatement TestFunctionIndentation TestFunctionTypePredicateFormatting -TestFormatAfterWhitespace -TestFormatAnyTypeLiteral -TestFormatEmptyBlock -TestFormatEmptyParamList -TestFormatonkey01 -TestFormatOnSemiColonAfterBreak -TestFormattingAfterMultiLineIfCondition -TestFormattingBlockInCaseClauses -TestFormattingEqualsBeforeBracketInTypeAlias -TestFormattingIfInElseBlock -TestFormattingInExpressionsInTsx -TestFormattingOfChainedLambda -TestFormattingOnCloseBrace -TestFormattingOnDoWhileNoSemicolon -TestFormattingOnEnter -TestFormattingOnNestedDoWhileByEnter -TestFormattingOnSemiColon -TestFormattingSpaceAfterCommaBeforeOpenParen -TestFormattingTemplates -TestFormattingWithMultilineComments -TestFunctionTypeFormatting TestFunduleWithRecursiveReference TestGenericCombinators3 TestGenericCombinatorWithConstraints1 @@ -406,7 +381,6 @@ TestImportCompletionsPackageJsonImportsPattern2 TestImportFixesGlobalTypingsCache TestImportMetaCompletionDetails TestImportNameCodeFix_avoidRelativeNodeModules -TestImportNameCodeFix_externalNonRelateive2 TestImportNameCodeFix_externalNonRelative1 TestImportNameCodeFix_fileWithNoTrailingNewline TestImportNameCodeFix_HeaderComment1 @@ -500,8 +474,6 @@ TestMemberListInReopenedEnum TestMemberListInWithBlock TestMemberListOfExportedClass TestMemberListOnContextualThis -TestModuleNodeNextAutoImport2 -TestModuleNodeNextAutoImport3 TestMultilineCommentBeforeOpenBrace TestMultiModuleFundule TestNgProxy1 @@ -514,7 +486,6 @@ TestOptionalPropertyFormatting TestOverloadQuickInfo TestParameterWithDestructuring TestParameterWithNestedDestructuring -TestPaste TestPathCompletionsAllowModuleAugmentationExtensions TestPathCompletionsAllowTsExtensions TestPathCompletionsPackageJsonExportsBundlerNoNodeCondition @@ -685,12 +656,8 @@ TestRenamePrivateFields TestReverseMappedTypeQuickInfo TestSelfReferencedExternalModule TestSemicolonFormattingNestedStatements -TestSpaceAfterReturn -TestSemicolonFormatting -TestSemicolonFormattingAfterArrayLiteral -TestSemicolonFormattingNestedStatements TestSignatureHelpCallExpressionJs -TestSpaceAfterConstructor +TestSpaceAfterReturn TestStringCompletionsImportOrExportSpecifier TestStringCompletionsVsEscaping TestSymbolCompletionLowerPriority @@ -715,7 +682,6 @@ TestTsxQuickInfo7 TestTypeCheckAfterResolve TestTypeOperatorNodeBuilding TestUnclosedStringLiteralAutoformating -TestWhiteSpaceBeforeReturnTypeFormatting TestWhiteSpaceTrimming TestWhiteSpaceTrimming2 TestWhiteSpaceTrimming4 diff --git a/internal/fourslash/tests/gen/asOperatorFormatting_test.go b/internal/fourslash/tests/gen/asOperatorFormatting_test.go index f6cb9dce88..e6ccb65428 100644 --- a/internal/fourslash/tests/gen/asOperatorFormatting_test.go +++ b/internal/fourslash/tests/gen/asOperatorFormatting_test.go @@ -8,8 +8,8 @@ import ( ) func TestAsOperatorFormatting(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/**/var x = 3 as number;` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/autoFormattingOnPasting_test.go b/internal/fourslash/tests/gen/autoFormattingOnPasting_test.go index f99825aa65..f466d337cf 100644 --- a/internal/fourslash/tests/gen/autoFormattingOnPasting_test.go +++ b/internal/fourslash/tests/gen/autoFormattingOnPasting_test.go @@ -8,13 +8,8 @@ import ( ) func TestAutoFormattingOnPasting(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - t.Skip() -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `module TestModule { /**/ @@ -23,14 +18,10 @@ func TestAutoFormattingOnPasting(t *testing.T) { defer done() f.GoToMarker(t, "") f.Paste(t, " class TestClass{\nprivate foo;\npublic testMethod( )\n{}\n}") -<<<<<<< HEAD f.VerifyCurrentFileContent(t, `module TestModule { class TestClass { private foo; public testMethod() { } } }`) -======= - f.VerifyCurrentFileContentIs(t, "module TestModule {\n class TestClass {\n private foo;\n public testMethod() { }\n }\n}") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/autoImportProvider1_test.go b/internal/fourslash/tests/gen/autoImportProvider1_test.go index 4df8d5edbc..818e62263e 100644 --- a/internal/fourslash/tests/gen/autoImportProvider1_test.go +++ b/internal/fourslash/tests/gen/autoImportProvider1_test.go @@ -8,8 +8,8 @@ import ( ) func TestAutoImportProvider1(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @Filename: /home/src/workspaces/project/node_modules/@angular/forms/package.json { "name": "@angular/forms", "typings": "./forms.d.ts" } diff --git a/internal/fourslash/tests/gen/autoImportProvider2_test.go b/internal/fourslash/tests/gen/autoImportProvider2_test.go index cb9ce40c11..48721aac25 100644 --- a/internal/fourslash/tests/gen/autoImportProvider2_test.go +++ b/internal/fourslash/tests/gen/autoImportProvider2_test.go @@ -8,8 +8,8 @@ import ( ) func TestAutoImportProvider2(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @Filename: /home/src/workspaces/project/node_modules/direct-dependency/package.json { "name": "direct-dependency", "dependencies": { "indirect-dependency": "*" } } diff --git a/internal/fourslash/tests/gen/autoImportProvider7_test.go b/internal/fourslash/tests/gen/autoImportProvider7_test.go index b81b702e24..94f4ccb504 100644 --- a/internal/fourslash/tests/gen/autoImportProvider7_test.go +++ b/internal/fourslash/tests/gen/autoImportProvider7_test.go @@ -11,8 +11,8 @@ import ( ) func TestAutoImportProvider7(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @Filename: /home/src/workspaces/project/tsconfig.json { "compilerOptions": { "module": "commonjs" } } diff --git a/internal/fourslash/tests/gen/autoImportProvider8_test.go b/internal/fourslash/tests/gen/autoImportProvider8_test.go index 5339ac91d1..4633833b6a 100644 --- a/internal/fourslash/tests/gen/autoImportProvider8_test.go +++ b/internal/fourslash/tests/gen/autoImportProvider8_test.go @@ -11,8 +11,8 @@ import ( ) func TestAutoImportProvider8(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @Filename: /home/src/workspaces/project/tsconfig.json { "compilerOptions": { "module": "commonjs" } } diff --git a/internal/fourslash/tests/gen/chainedFatArrowFormatting_test.go b/internal/fourslash/tests/gen/chainedFatArrowFormatting_test.go index 8d128fd08e..96fa8fb1aa 100644 --- a/internal/fourslash/tests/gen/chainedFatArrowFormatting_test.go +++ b/internal/fourslash/tests/gen/chainedFatArrowFormatting_test.go @@ -8,22 +8,13 @@ import ( ) func TestChainedFatArrowFormatting(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `var fn = () => () => null/**/` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) defer done() f.GoToMarker(t, "") f.Insert(t, ";") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, `var fn = () => () => null;`) -======= - f.VerifyCurrentLineContentIs(t, "var fn = () => () => null;") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/commentsBlocks_test.go b/internal/fourslash/tests/gen/commentsBlocks_test.go index c9d7d4cfef..7de08dd7f2 100644 --- a/internal/fourslash/tests/gen/commentsBlocks_test.go +++ b/internal/fourslash/tests/gen/commentsBlocks_test.go @@ -8,8 +8,8 @@ import ( ) func TestCommentsBlocks(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*1*/// 1 var x, diff --git a/internal/fourslash/tests/gen/completionsImport_addToNamedWithDifferentCacheValue_test.go b/internal/fourslash/tests/gen/completionsImport_addToNamedWithDifferentCacheValue_test.go index 583d90b54e..a9256e0873 100644 --- a/internal/fourslash/tests/gen/completionsImport_addToNamedWithDifferentCacheValue_test.go +++ b/internal/fourslash/tests/gen/completionsImport_addToNamedWithDifferentCacheValue_test.go @@ -11,8 +11,8 @@ import ( ) func TestCompletionsImport_addToNamedWithDifferentCacheValue(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @Filename: /home/src/workspaces/project/tsconfig.json { "compilerOptions": { "module": "commonjs" } } diff --git a/internal/fourslash/tests/gen/completionsImport_jsModuleExportsAssignment_test.go b/internal/fourslash/tests/gen/completionsImport_jsModuleExportsAssignment_test.go index d87cc49c47..57ea302a81 100644 --- a/internal/fourslash/tests/gen/completionsImport_jsModuleExportsAssignment_test.go +++ b/internal/fourslash/tests/gen/completionsImport_jsModuleExportsAssignment_test.go @@ -11,8 +11,8 @@ import ( ) func TestCompletionsImport_jsModuleExportsAssignment(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @Filename: /home/src/workspaces/project/tsconfig.json { "compilerOptions": { "module": "commonjs", "allowJs": true } } diff --git a/internal/fourslash/tests/gen/consistenceOnIndentionsOfObjectsInAListAfterFormatting_test.go b/internal/fourslash/tests/gen/consistenceOnIndentionsOfObjectsInAListAfterFormatting_test.go index 34df99fceb..e66edd9dff 100644 --- a/internal/fourslash/tests/gen/consistenceOnIndentionsOfObjectsInAListAfterFormatting_test.go +++ b/internal/fourslash/tests/gen/consistenceOnIndentionsOfObjectsInAListAfterFormatting_test.go @@ -8,8 +8,8 @@ import ( ) func TestConsistenceOnIndentionsOfObjectsInAListAfterFormatting(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `foo({ }, {/*1*/ diff --git a/internal/fourslash/tests/gen/constructorBraceFormatting_test.go b/internal/fourslash/tests/gen/constructorBraceFormatting_test.go index 8281bc6ee9..0ee2d43fe7 100644 --- a/internal/fourslash/tests/gen/constructorBraceFormatting_test.go +++ b/internal/fourslash/tests/gen/constructorBraceFormatting_test.go @@ -8,13 +8,8 @@ import ( ) func TestConstructorBraceFormatting(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class X { constructor () {}/*target*/ @@ -24,9 +19,5 @@ func TestConstructorBraceFormatting(t *testing.T) { f.GoToMarker(t, "") f.Insert(t, "}") f.GoToMarker(t, "target") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, ` constructor() { }`) -======= - f.VerifyCurrentLineContentIs(t, " constructor() { }") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/forceIndentAfterNewLineInsert_test.go b/internal/fourslash/tests/gen/forceIndentAfterNewLineInsert_test.go index 2c4f16a083..bd809091bc 100644 --- a/internal/fourslash/tests/gen/forceIndentAfterNewLineInsert_test.go +++ b/internal/fourslash/tests/gen/forceIndentAfterNewLineInsert_test.go @@ -8,8 +8,8 @@ import ( ) func TestForceIndentAfterNewLineInsert(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `function f1() { return 0; } diff --git a/internal/fourslash/tests/gen/format01_test.go b/internal/fourslash/tests/gen/format01_test.go index bc4bd22c6e..e71a216a51 100644 --- a/internal/fourslash/tests/gen/format01_test.go +++ b/internal/fourslash/tests/gen/format01_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormat01(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/**/module Default{var x= ( { } ) ;}` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formatAfterMultilineComment_test.go b/internal/fourslash/tests/gen/formatAfterMultilineComment_test.go index 40a12c87c3..904b9ffd33 100644 --- a/internal/fourslash/tests/gen/formatAfterMultilineComment_test.go +++ b/internal/fourslash/tests/gen/formatAfterMultilineComment_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatAfterMultilineComment(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*foo */"123123";` diff --git a/internal/fourslash/tests/gen/formatAfterObjectLiteral_test.go b/internal/fourslash/tests/gen/formatAfterObjectLiteral_test.go index a34a88e249..20f458ecd2 100644 --- a/internal/fourslash/tests/gen/formatAfterObjectLiteral_test.go +++ b/internal/fourslash/tests/gen/formatAfterObjectLiteral_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatAfterObjectLiteral(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/**/module Default{var x= ( { } ) ;}` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formatAfterPasteInString_test.go b/internal/fourslash/tests/gen/formatAfterPasteInString_test.go index 274e5a4a9f..5a4afd8efe 100644 --- a/internal/fourslash/tests/gen/formatAfterPasteInString_test.go +++ b/internal/fourslash/tests/gen/formatAfterPasteInString_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatAfterPasteInString(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*2*/const x = f('aa/*1*/a').x()` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formatAfterWhitespace_test.go b/internal/fourslash/tests/gen/formatAfterWhitespace_test.go index a8d3c48c7d..eace515298 100644 --- a/internal/fourslash/tests/gen/formatAfterWhitespace_test.go +++ b/internal/fourslash/tests/gen/formatAfterWhitespace_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormatAfterWhitespace(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `function foo() { @@ -25,14 +20,10 @@ func TestFormatAfterWhitespace(t *testing.T) { defer done() f.GoToMarker(t, "1") f.InsertLine(t, "") -<<<<<<< HEAD f.VerifyCurrentFileContent(t, `function foo() { var bar; }`) -======= - f.VerifyCurrentFileContentIs(t, "function foo()\n{\n var bar;\n\n\n}") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formatAnyTypeLiteral_test.go b/internal/fourslash/tests/gen/formatAnyTypeLiteral_test.go index 558cae9a57..e12670e1aa 100644 --- a/internal/fourslash/tests/gen/formatAnyTypeLiteral_test.go +++ b/internal/fourslash/tests/gen/formatAnyTypeLiteral_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormatAnyTypeLiteral(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `function foo(x: { } /*objLit*/){ /**/` @@ -23,9 +18,5 @@ func TestFormatAnyTypeLiteral(t *testing.T) { f.GoToMarker(t, "") f.Insert(t, "}") f.GoToMarker(t, "objLit") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, `function foo(x: {}) {`) -======= - f.VerifyCurrentLineContentIs(t, "function foo(x: {}) {") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formatArrayLiteralExpression_test.go b/internal/fourslash/tests/gen/formatArrayLiteralExpression_test.go index 66ed2fc0f8..49631f1609 100644 --- a/internal/fourslash/tests/gen/formatArrayLiteralExpression_test.go +++ b/internal/fourslash/tests/gen/formatArrayLiteralExpression_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatArrayLiteralExpression(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `export let Things = [{ Hat: 'hat', /*1*/ diff --git a/internal/fourslash/tests/gen/formatArrayOrObjectLiteralsInVariableList_test.go b/internal/fourslash/tests/gen/formatArrayOrObjectLiteralsInVariableList_test.go index 03fe70126f..9edc5e806d 100644 --- a/internal/fourslash/tests/gen/formatArrayOrObjectLiteralsInVariableList_test.go +++ b/internal/fourslash/tests/gen/formatArrayOrObjectLiteralsInVariableList_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatArrayOrObjectLiteralsInVariableList(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `var v30 = [1, 2], v31, v32, v33 = [0], v34 = {'a': true}, v35;/**/` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formatAsyncClassMethod1_test.go b/internal/fourslash/tests/gen/formatAsyncClassMethod1_test.go index 1e0e8affda..a026f97985 100644 --- a/internal/fourslash/tests/gen/formatAsyncClassMethod1_test.go +++ b/internal/fourslash/tests/gen/formatAsyncClassMethod1_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatAsyncClassMethod1(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class Foo { async foo() {} diff --git a/internal/fourslash/tests/gen/formatAsyncClassMethod2_test.go b/internal/fourslash/tests/gen/formatAsyncClassMethod2_test.go index 254c599e05..b2d9ac1659 100644 --- a/internal/fourslash/tests/gen/formatAsyncClassMethod2_test.go +++ b/internal/fourslash/tests/gen/formatAsyncClassMethod2_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatAsyncClassMethod2(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class Foo { private async foo() {} diff --git a/internal/fourslash/tests/gen/formatAsyncComputedMethod_test.go b/internal/fourslash/tests/gen/formatAsyncComputedMethod_test.go index 35daef47e1..6ec6975890 100644 --- a/internal/fourslash/tests/gen/formatAsyncComputedMethod_test.go +++ b/internal/fourslash/tests/gen/formatAsyncComputedMethod_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatAsyncComputedMethod(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class C { /*method*/async [0]() { } diff --git a/internal/fourslash/tests/gen/formatAsyncKeyword_test.go b/internal/fourslash/tests/gen/formatAsyncKeyword_test.go index a90034aeb4..efa2a36a0c 100644 --- a/internal/fourslash/tests/gen/formatAsyncKeyword_test.go +++ b/internal/fourslash/tests/gen/formatAsyncKeyword_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatAsyncKeyword(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*1*/let x = async () => 1; /*2*/let y = async() => 1; diff --git a/internal/fourslash/tests/gen/formatBracketInSwitchCase_test.go b/internal/fourslash/tests/gen/formatBracketInSwitchCase_test.go index 5e8964255f..5ed280e4e2 100644 --- a/internal/fourslash/tests/gen/formatBracketInSwitchCase_test.go +++ b/internal/fourslash/tests/gen/formatBracketInSwitchCase_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatBracketInSwitchCase(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `switch (x) { case[]: diff --git a/internal/fourslash/tests/gen/formatColonAndQMark_test.go b/internal/fourslash/tests/gen/formatColonAndQMark_test.go index 5f861d540d..9fec50c5c7 100644 --- a/internal/fourslash/tests/gen/formatColonAndQMark_test.go +++ b/internal/fourslash/tests/gen/formatColonAndQMark_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatColonAndQMark(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class foo {/*1*/ constructor (n?: number, m = 5, o?: string) { }/*2*/ diff --git a/internal/fourslash/tests/gen/formatComments_test.go b/internal/fourslash/tests/gen/formatComments_test.go index 0f8ae05317..9fed00c20d 100644 --- a/internal/fourslash/tests/gen/formatComments_test.go +++ b/internal/fourslash/tests/gen/formatComments_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatComments(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `_.chain() // wow/*callChain1*/ diff --git a/internal/fourslash/tests/gen/formatConflictDiff3Marker1_test.go b/internal/fourslash/tests/gen/formatConflictDiff3Marker1_test.go index 1015d9928c..27b21a8712 100644 --- a/internal/fourslash/tests/gen/formatConflictDiff3Marker1_test.go +++ b/internal/fourslash/tests/gen/formatConflictDiff3Marker1_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatConflictDiff3Marker1(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class C { <<<<<<< HEAD diff --git a/internal/fourslash/tests/gen/formatConflictMarker1_test.go b/internal/fourslash/tests/gen/formatConflictMarker1_test.go index 76ef4931e8..8a5c279585 100644 --- a/internal/fourslash/tests/gen/formatConflictMarker1_test.go +++ b/internal/fourslash/tests/gen/formatConflictMarker1_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatConflictMarker1(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class C { <<<<<<< HEAD diff --git a/internal/fourslash/tests/gen/formatControlFlowConstructs_test.go b/internal/fourslash/tests/gen/formatControlFlowConstructs_test.go index 35499f198f..bedd66171c 100644 --- a/internal/fourslash/tests/gen/formatControlFlowConstructs_test.go +++ b/internal/fourslash/tests/gen/formatControlFlowConstructs_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatControlFlowConstructs(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `if (true)/**/ { diff --git a/internal/fourslash/tests/gen/formatDebuggerStatement_test.go b/internal/fourslash/tests/gen/formatDebuggerStatement_test.go index 3739025761..8a97d2c4e7 100644 --- a/internal/fourslash/tests/gen/formatDebuggerStatement_test.go +++ b/internal/fourslash/tests/gen/formatDebuggerStatement_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatDebuggerStatement(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `if(false){debugger;} if ( false ) { debugger ; }` diff --git a/internal/fourslash/tests/gen/formatDocumentPreserveTrailingWhitespace_test.go b/internal/fourslash/tests/gen/formatDocumentPreserveTrailingWhitespace_test.go index a43e4cb786..7453579cd9 100644 --- a/internal/fourslash/tests/gen/formatDocumentPreserveTrailingWhitespace_test.go +++ b/internal/fourslash/tests/gen/formatDocumentPreserveTrailingWhitespace_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatDocumentPreserveTrailingWhitespace(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = ` var a; diff --git a/internal/fourslash/tests/gen/formatDocumentWithJSDoc_test.go b/internal/fourslash/tests/gen/formatDocumentWithJSDoc_test.go index 6e45b393af..fc991cff8c 100644 --- a/internal/fourslash/tests/gen/formatDocumentWithJSDoc_test.go +++ b/internal/fourslash/tests/gen/formatDocumentWithJSDoc_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatDocumentWithJSDoc(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/** * JSDoc for things diff --git a/internal/fourslash/tests/gen/formatDocumentWithTrivia_test.go b/internal/fourslash/tests/gen/formatDocumentWithTrivia_test.go index 933f71b799..4537afa63e 100644 --- a/internal/fourslash/tests/gen/formatDocumentWithTrivia_test.go +++ b/internal/fourslash/tests/gen/formatDocumentWithTrivia_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatDocumentWithTrivia(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = ` // 1 below diff --git a/internal/fourslash/tests/gen/formatDotAfterNumber_test.go b/internal/fourslash/tests/gen/formatDotAfterNumber_test.go index 03c96b43f3..718564ff1f 100644 --- a/internal/fourslash/tests/gen/formatDotAfterNumber_test.go +++ b/internal/fourslash/tests/gen/formatDotAfterNumber_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatDotAfterNumber(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `1+ 2 .toString() +3/*1*/ 1+ 2. .toString() +3/*2*/ diff --git a/internal/fourslash/tests/gen/formatEmptyBlock_test.go b/internal/fourslash/tests/gen/formatEmptyBlock_test.go index 08b80d11ac..784e999417 100644 --- a/internal/fourslash/tests/gen/formatEmptyBlock_test.go +++ b/internal/fourslash/tests/gen/formatEmptyBlock_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormatEmptyBlock(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `{}` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) @@ -22,9 +17,5 @@ func TestFormatEmptyBlock(t *testing.T) { f.GoToEOF(t) f.Insert(t, "\n") f.GoToBOF(t) -<<<<<<< HEAD f.VerifyCurrentLineContent(t, `{ }`) -======= - f.VerifyCurrentLineContentIs(t, "{ }") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formatEmptyParamList_test.go b/internal/fourslash/tests/gen/formatEmptyParamList_test.go index 79cb5aa55a..d58961567d 100644 --- a/internal/fourslash/tests/gen/formatEmptyParamList_test.go +++ b/internal/fourslash/tests/gen/formatEmptyParamList_test.go @@ -8,22 +8,13 @@ import ( ) func TestFormatEmptyParamList(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - t.Skip() -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `function f( f: function){/*1*/` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) defer done() f.GoToMarker(t, "1") f.Insert(t, "}") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, `function f(f: function) { }`) -======= - f.VerifyCurrentLineContentIs(t, "function f(f: function) { }") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formatExportAssignment_test.go b/internal/fourslash/tests/gen/formatExportAssignment_test.go index 54e8896c72..5cf5506b24 100644 --- a/internal/fourslash/tests/gen/formatExportAssignment_test.go +++ b/internal/fourslash/tests/gen/formatExportAssignment_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatExportAssignment(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `export='foo';` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formatIfTryCatchBlocks_test.go b/internal/fourslash/tests/gen/formatIfTryCatchBlocks_test.go index c442a34945..2d9089ddc0 100644 --- a/internal/fourslash/tests/gen/formatIfTryCatchBlocks_test.go +++ b/internal/fourslash/tests/gen/formatIfTryCatchBlocks_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatIfTryCatchBlocks(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `try { } diff --git a/internal/fourslash/tests/gen/formatIfWithEmptyCondition_test.go b/internal/fourslash/tests/gen/formatIfWithEmptyCondition_test.go index 2c4bf360fa..cf63ca3b08 100644 --- a/internal/fourslash/tests/gen/formatIfWithEmptyCondition_test.go +++ b/internal/fourslash/tests/gen/formatIfWithEmptyCondition_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatIfWithEmptyCondition(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `if () { }` diff --git a/internal/fourslash/tests/gen/formatImplicitModule_test.go b/internal/fourslash/tests/gen/formatImplicitModule_test.go index 49d2680d8c..3628d1a916 100644 --- a/internal/fourslash/tests/gen/formatImplicitModule_test.go +++ b/internal/fourslash/tests/gen/formatImplicitModule_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatImplicitModule(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = ` export class A { diff --git a/internal/fourslash/tests/gen/formatImportDeclaration_test.go b/internal/fourslash/tests/gen/formatImportDeclaration_test.go index 0649847e5b..02e6fc86cb 100644 --- a/internal/fourslash/tests/gen/formatImportDeclaration_test.go +++ b/internal/fourslash/tests/gen/formatImportDeclaration_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatImportDeclaration(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `module Foo {/*1*/ }/*2*/ diff --git a/internal/fourslash/tests/gen/formatInTryCatchFinally_test.go b/internal/fourslash/tests/gen/formatInTryCatchFinally_test.go index 3b31ffdb5a..b0c2f56c88 100644 --- a/internal/fourslash/tests/gen/formatInTryCatchFinally_test.go +++ b/internal/fourslash/tests/gen/formatInTryCatchFinally_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormatInTryCatchFinally(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `try { @@ -27,9 +22,5 @@ catch (e) defer done() f.GoToMarker(t, "1") f.Insert(t, ";") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, ` var x = 1;`) -======= - f.VerifyCurrentLineContentIs(t, " var x = 1;") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formatInTsxFiles_test.go b/internal/fourslash/tests/gen/formatInTsxFiles_test.go index dc28bc5898..3418e29e12 100644 --- a/internal/fourslash/tests/gen/formatInTsxFiles_test.go +++ b/internal/fourslash/tests/gen/formatInTsxFiles_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatInTsxFiles(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `//@Filename: file.tsx interface I { diff --git a/internal/fourslash/tests/gen/formatInsertSpaceAfterCloseBraceBeforeCloseBracket_test.go b/internal/fourslash/tests/gen/formatInsertSpaceAfterCloseBraceBeforeCloseBracket_test.go index 7ec4a69fc4..3ddb36aecc 100644 --- a/internal/fourslash/tests/gen/formatInsertSpaceAfterCloseBraceBeforeCloseBracket_test.go +++ b/internal/fourslash/tests/gen/formatInsertSpaceAfterCloseBraceBeforeCloseBracket_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatInsertSpaceAfterCloseBraceBeforeCloseBracket(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `[{}]` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formatJsxWithKeywordInIdentifier_test.go b/internal/fourslash/tests/gen/formatJsxWithKeywordInIdentifier_test.go index 88b25c8bd0..31d70adba2 100644 --- a/internal/fourslash/tests/gen/formatJsxWithKeywordInIdentifier_test.go +++ b/internal/fourslash/tests/gen/formatJsxWithKeywordInIdentifier_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatJsxWithKeywordInIdentifier(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @Filename: /a.tsx
` diff --git a/internal/fourslash/tests/gen/formatLiteralTypeInUnionOrIntersectionType_test.go b/internal/fourslash/tests/gen/formatLiteralTypeInUnionOrIntersectionType_test.go index 3bc0447516..f8d02dca47 100644 --- a/internal/fourslash/tests/gen/formatLiteralTypeInUnionOrIntersectionType_test.go +++ b/internal/fourslash/tests/gen/formatLiteralTypeInUnionOrIntersectionType_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatLiteralTypeInUnionOrIntersectionType(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `type NumberAndString = { a: number diff --git a/internal/fourslash/tests/gen/formatMultilineComment_test.go b/internal/fourslash/tests/gen/formatMultilineComment_test.go index f817a1acd9..d632e08bfd 100644 --- a/internal/fourslash/tests/gen/formatMultilineComment_test.go +++ b/internal/fourslash/tests/gen/formatMultilineComment_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatMultilineComment(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*1*//** 1 */*2*/2 diff --git a/internal/fourslash/tests/gen/formatMultilineTypesWithMapped_test.go b/internal/fourslash/tests/gen/formatMultilineTypesWithMapped_test.go index 895d711ea1..bc72769c95 100644 --- a/internal/fourslash/tests/gen/formatMultilineTypesWithMapped_test.go +++ b/internal/fourslash/tests/gen/formatMultilineTypesWithMapped_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatMultilineTypesWithMapped(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `type Z = 'z' type A = { diff --git a/internal/fourslash/tests/gen/formatMultipleFunctionArguments_test.go b/internal/fourslash/tests/gen/formatMultipleFunctionArguments_test.go index f781b0c3b7..b071986d17 100644 --- a/internal/fourslash/tests/gen/formatMultipleFunctionArguments_test.go +++ b/internal/fourslash/tests/gen/formatMultipleFunctionArguments_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatMultipleFunctionArguments(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = ` someRandomFunction({ diff --git a/internal/fourslash/tests/gen/formatNestedClassWithOpenBraceOnNewLines_test.go b/internal/fourslash/tests/gen/formatNestedClassWithOpenBraceOnNewLines_test.go index 2a67ad12dc..9ad97a5391 100644 --- a/internal/fourslash/tests/gen/formatNestedClassWithOpenBraceOnNewLines_test.go +++ b/internal/fourslash/tests/gen/formatNestedClassWithOpenBraceOnNewLines_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatNestedClassWithOpenBraceOnNewLines(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `module A { diff --git a/internal/fourslash/tests/gen/formatNoSpaceAfterTemplateHeadAndMiddle_test.go b/internal/fourslash/tests/gen/formatNoSpaceAfterTemplateHeadAndMiddle_test.go index 780f9bc6a7..3577e26b8f 100644 --- a/internal/fourslash/tests/gen/formatNoSpaceAfterTemplateHeadAndMiddle_test.go +++ b/internal/fourslash/tests/gen/formatNoSpaceAfterTemplateHeadAndMiddle_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatNoSpaceAfterTemplateHeadAndMiddle(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `const a1 = ` + "`" + `${ 1 }${ 1 }` + "`" + `; const a2 = ` + "`" + ` diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace1_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace1_test.go index 7b85553d7a..1e4c1ba1ad 100644 --- a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace1_test.go +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace1_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatNoSpaceBeforeCloseBrace1(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `new Foo(1, /* comment */ );` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace2_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace2_test.go index 1c8735b8a5..537842db7d 100644 --- a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace2_test.go +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace2_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatNoSpaceBeforeCloseBrace2(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `new Foo(1, );` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace3_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace3_test.go index a10e4fbbbb..870d0d1db9 100644 --- a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace3_test.go +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace3_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatNoSpaceBeforeCloseBrace3(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `foo( 1, /* comment */ );` diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace4_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace4_test.go index 139af8917d..8cfbd0ac13 100644 --- a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace4_test.go +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace4_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatNoSpaceBeforeCloseBrace4(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `new Foo(1 , /* comment */ );` diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace5_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace5_test.go index 3b85a3ab16..fe85e96d37 100644 --- a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace5_test.go +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace5_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatNoSpaceBeforeCloseBrace5(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `new Foo(1, /* comment */ );` diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace6_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace6_test.go index 9c31fb4e62..fda3568204 100644 --- a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace6_test.go +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace6_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatNoSpaceBeforeCloseBrace6(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `new Foo(1, /* comment */ );` diff --git a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace_test.go b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace_test.go index b93fb4be25..b3613ae2e7 100644 --- a/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace_test.go +++ b/internal/fourslash/tests/gen/formatNoSpaceBeforeCloseBrace_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatNoSpaceBeforeCloseBrace(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `foo(1, /* comment */ );` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formatNoSpaceBetweenClosingParenAndTemplateString_test.go b/internal/fourslash/tests/gen/formatNoSpaceBetweenClosingParenAndTemplateString_test.go index af248c75e1..de8a95b077 100644 --- a/internal/fourslash/tests/gen/formatNoSpaceBetweenClosingParenAndTemplateString_test.go +++ b/internal/fourslash/tests/gen/formatNoSpaceBetweenClosingParenAndTemplateString_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatNoSpaceBetweenClosingParenAndTemplateString(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `foo() ` + "`" + `abc` + "`" + `; bar()` + "`" + `def` + "`" + `; diff --git a/internal/fourslash/tests/gen/formatObjectBindingPattern_restElementWithPropertyName_test.go b/internal/fourslash/tests/gen/formatObjectBindingPattern_restElementWithPropertyName_test.go index 78bfa16efe..1eeebb217e 100644 --- a/internal/fourslash/tests/gen/formatObjectBindingPattern_restElementWithPropertyName_test.go +++ b/internal/fourslash/tests/gen/formatObjectBindingPattern_restElementWithPropertyName_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatObjectBindingPattern_restElementWithPropertyName(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `const { ...a: b } = {};` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formatObjectBindingPattern_test.go b/internal/fourslash/tests/gen/formatObjectBindingPattern_test.go index 9b19da613b..268e63a914 100644 --- a/internal/fourslash/tests/gen/formatObjectBindingPattern_test.go +++ b/internal/fourslash/tests/gen/formatObjectBindingPattern_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatObjectBindingPattern(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `const { x, diff --git a/internal/fourslash/tests/gen/formatOnEnterFunctionDeclaration_test.go b/internal/fourslash/tests/gen/formatOnEnterFunctionDeclaration_test.go index 9fcd95ef26..ae6164e315 100644 --- a/internal/fourslash/tests/gen/formatOnEnterFunctionDeclaration_test.go +++ b/internal/fourslash/tests/gen/formatOnEnterFunctionDeclaration_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormatOnEnterFunctionDeclaration(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*0*/function listAPIFiles(path: string): string[] {/*1*/ }` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) @@ -22,9 +17,5 @@ func TestFormatOnEnterFunctionDeclaration(t *testing.T) { f.GoToMarker(t, "1") f.InsertLine(t, "") f.GoToMarker(t, "0") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, `function listAPIFiles(path: string): string[] {`) -======= - f.VerifyCurrentLineContentIs(t, "function listAPIFiles(path: string): string[] {") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formatOnEnterInComment_test.go b/internal/fourslash/tests/gen/formatOnEnterInComment_test.go index de2a483b9d..559a6e81f3 100644 --- a/internal/fourslash/tests/gen/formatOnEnterInComment_test.go +++ b/internal/fourslash/tests/gen/formatOnEnterInComment_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormatOnEnterInComment(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = ` /** * /*1*/ @@ -23,12 +18,8 @@ func TestFormatOnEnterInComment(t *testing.T) { defer done() f.GoToMarker(t, "1") f.InsertLine(t, "") -<<<<<<< HEAD f.VerifyCurrentFileContent(t, ` /** * */`) -======= - f.VerifyCurrentFileContentIs(t, " /**\n * \n\n */") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formatOnEnterOpenBraceAddNewLine_test.go b/internal/fourslash/tests/gen/formatOnEnterOpenBraceAddNewLine_test.go index 2741fbb9f5..ea8f946898 100644 --- a/internal/fourslash/tests/gen/formatOnEnterOpenBraceAddNewLine_test.go +++ b/internal/fourslash/tests/gen/formatOnEnterOpenBraceAddNewLine_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatOnEnterOpenBraceAddNewLine(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `if(true) {/*0*/} if(false)/*1*/{ diff --git a/internal/fourslash/tests/gen/formatOnOpenCurlyBraceRemoveNewLine_test.go b/internal/fourslash/tests/gen/formatOnOpenCurlyBraceRemoveNewLine_test.go index 9c3127855e..4da4941b62 100644 --- a/internal/fourslash/tests/gen/formatOnOpenCurlyBraceRemoveNewLine_test.go +++ b/internal/fourslash/tests/gen/formatOnOpenCurlyBraceRemoveNewLine_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatOnOpenCurlyBraceRemoveNewLine(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `if(true) /**/ }` diff --git a/internal/fourslash/tests/gen/formatOnSemiColonAfterBreak_test.go b/internal/fourslash/tests/gen/formatOnSemiColonAfterBreak_test.go index 8b7af7fd4e..86f822dc6b 100644 --- a/internal/fourslash/tests/gen/formatOnSemiColonAfterBreak_test.go +++ b/internal/fourslash/tests/gen/formatOnSemiColonAfterBreak_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormatOnSemiColonAfterBreak(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - t.Skip() -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `for (var a in b) { break/**/ @@ -23,9 +18,5 @@ break/**/ defer done() f.GoToMarker(t, "") f.Insert(t, ";") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, ` break;`) -======= - f.VerifyCurrentLineContentIs(t, " break;") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formatParameter_test.go b/internal/fourslash/tests/gen/formatParameter_test.go index 8abf36ee99..f7ee996df9 100644 --- a/internal/fourslash/tests/gen/formatParameter_test.go +++ b/internal/fourslash/tests/gen/formatParameter_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatParameter(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `function foo( first: diff --git a/internal/fourslash/tests/gen/formatRemoveNewLineAfterOpenBrace_test.go b/internal/fourslash/tests/gen/formatRemoveNewLineAfterOpenBrace_test.go index 68da02fd12..2103e0c03e 100644 --- a/internal/fourslash/tests/gen/formatRemoveNewLineAfterOpenBrace_test.go +++ b/internal/fourslash/tests/gen/formatRemoveNewLineAfterOpenBrace_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatRemoveNewLineAfterOpenBrace(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `function foo() { diff --git a/internal/fourslash/tests/gen/formatRemoveSpaceBetweenDotDotDotAndTypeName_test.go b/internal/fourslash/tests/gen/formatRemoveSpaceBetweenDotDotDotAndTypeName_test.go index 9bb6b7c7e0..fe1256d3e6 100644 --- a/internal/fourslash/tests/gen/formatRemoveSpaceBetweenDotDotDotAndTypeName_test.go +++ b/internal/fourslash/tests/gen/formatRemoveSpaceBetweenDotDotDotAndTypeName_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatRemoveSpaceBetweenDotDotDotAndTypeName(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `let a: [... any[]]; let b: [... number[]]; diff --git a/internal/fourslash/tests/gen/formatSatisfiesExpression_test.go b/internal/fourslash/tests/gen/formatSatisfiesExpression_test.go index 5d61e1fd0b..12fe648166 100644 --- a/internal/fourslash/tests/gen/formatSatisfiesExpression_test.go +++ b/internal/fourslash/tests/gen/formatSatisfiesExpression_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatSatisfiesExpression(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `type Foo = "a" | "b" | "c"; const foo1 = ["a"] satisfies Foo[]; diff --git a/internal/fourslash/tests/gen/formatSpaceAfterImplementsExtends_test.go b/internal/fourslash/tests/gen/formatSpaceAfterImplementsExtends_test.go index f866052d4b..a521d69286 100644 --- a/internal/fourslash/tests/gen/formatSpaceAfterImplementsExtends_test.go +++ b/internal/fourslash/tests/gen/formatSpaceAfterImplementsExtends_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatSpaceAfterImplementsExtends(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class C1 implements Array{ } diff --git a/internal/fourslash/tests/gen/formatSpaceAfterTemplateHeadAndMiddle_test.go b/internal/fourslash/tests/gen/formatSpaceAfterTemplateHeadAndMiddle_test.go index 0bc31df184..64d6aef9db 100644 --- a/internal/fourslash/tests/gen/formatSpaceAfterTemplateHeadAndMiddle_test.go +++ b/internal/fourslash/tests/gen/formatSpaceAfterTemplateHeadAndMiddle_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatSpaceAfterTemplateHeadAndMiddle(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `const a1 = ` + "`" + `${1}${1}` + "`" + `; const a2 = ` + "`" + ` diff --git a/internal/fourslash/tests/gen/formatSpaceBetweenFunctionAndArrayIndex_test.go b/internal/fourslash/tests/gen/formatSpaceBetweenFunctionAndArrayIndex_test.go index efc680cce8..a2dc12b44a 100644 --- a/internal/fourslash/tests/gen/formatSpaceBetweenFunctionAndArrayIndex_test.go +++ b/internal/fourslash/tests/gen/formatSpaceBetweenFunctionAndArrayIndex_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatSpaceBetweenFunctionAndArrayIndex(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = ` function test() { diff --git a/internal/fourslash/tests/gen/formatTSXWithInlineComment_test.go b/internal/fourslash/tests/gen/formatTSXWithInlineComment_test.go index 614022116c..672cad19c9 100644 --- a/internal/fourslash/tests/gen/formatTSXWithInlineComment_test.go +++ b/internal/fourslash/tests/gen/formatTSXWithInlineComment_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatTSXWithInlineComment(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @Filename: foo.tsx const a =
diff --git a/internal/fourslash/tests/gen/formatTryCatch_test.go b/internal/fourslash/tests/gen/formatTryCatch_test.go index 0025776f04..813eb7481a 100644 --- a/internal/fourslash/tests/gen/formatTryCatch_test.go +++ b/internal/fourslash/tests/gen/formatTryCatch_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatTryCatch(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `function test() { /*try*/try { diff --git a/internal/fourslash/tests/gen/formatTryFinally_test.go b/internal/fourslash/tests/gen/formatTryFinally_test.go index e5c531a041..0b6db74e71 100644 --- a/internal/fourslash/tests/gen/formatTryFinally_test.go +++ b/internal/fourslash/tests/gen/formatTryFinally_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatTryFinally(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `if (true) try { // ... diff --git a/internal/fourslash/tests/gen/formatTsxClosingAfterJsxText_test.go b/internal/fourslash/tests/gen/formatTsxClosingAfterJsxText_test.go index f6908c72bc..8317ee2312 100644 --- a/internal/fourslash/tests/gen/formatTsxClosingAfterJsxText_test.go +++ b/internal/fourslash/tests/gen/formatTsxClosingAfterJsxText_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatTsxClosingAfterJsxText(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @Filename: foo.tsx diff --git a/internal/fourslash/tests/gen/formatTsxMultilineAttributeString_test.go b/internal/fourslash/tests/gen/formatTsxMultilineAttributeString_test.go index 8d2a939713..9e25f2ab9b 100644 --- a/internal/fourslash/tests/gen/formatTsxMultilineAttributeString_test.go +++ b/internal/fourslash/tests/gen/formatTsxMultilineAttributeString_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatTsxMultilineAttributeString(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @Filename: foo.tsx ( diff --git a/internal/fourslash/tests/gen/formatTsx_test.go b/internal/fourslash/tests/gen/formatTsx_test.go index 9de78e0383..543adf277f 100644 --- a/internal/fourslash/tests/gen/formatTsx_test.go +++ b/internal/fourslash/tests/gen/formatTsx_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatTsx(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @Filename: foo.tsx

'

{function(){return 1;}]}

` diff --git a/internal/fourslash/tests/gen/formatTypeAnnotation1_test.go b/internal/fourslash/tests/gen/formatTypeAnnotation1_test.go index 6c501cc988..da3f75abbd 100644 --- a/internal/fourslash/tests/gen/formatTypeAnnotation1_test.go +++ b/internal/fourslash/tests/gen/formatTypeAnnotation1_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatTypeAnnotation1(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `function foo(x: number, y?: string): number {} interface Foo { diff --git a/internal/fourslash/tests/gen/formatTypeAnnotation2_test.go b/internal/fourslash/tests/gen/formatTypeAnnotation2_test.go index 62cb057f97..99b364b3ed 100644 --- a/internal/fourslash/tests/gen/formatTypeAnnotation2_test.go +++ b/internal/fourslash/tests/gen/formatTypeAnnotation2_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatTypeAnnotation2(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `function foo(x : number, y ?: string) : number {} interface Foo { diff --git a/internal/fourslash/tests/gen/formatTypeArgumentOnNewLine_test.go b/internal/fourslash/tests/gen/formatTypeArgumentOnNewLine_test.go index 0a400531d4..d3562372af 100644 --- a/internal/fourslash/tests/gen/formatTypeArgumentOnNewLine_test.go +++ b/internal/fourslash/tests/gen/formatTypeArgumentOnNewLine_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatTypeArgumentOnNewLine(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `const genericObject = new GenericObject< /*1*/{} diff --git a/internal/fourslash/tests/gen/formatTypeParameters_test.go b/internal/fourslash/tests/gen/formatTypeParameters_test.go index 23fe8fb8b4..822ade1f0d 100644 --- a/internal/fourslash/tests/gen/formatTypeParameters_test.go +++ b/internal/fourslash/tests/gen/formatTypeParameters_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatTypeParameters(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/**/type Bar = T` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formatVariableDeclarationList_test.go b/internal/fourslash/tests/gen/formatVariableDeclarationList_test.go index 6484728cef..cffd0764f6 100644 --- a/internal/fourslash/tests/gen/formatVariableDeclarationList_test.go +++ b/internal/fourslash/tests/gen/formatVariableDeclarationList_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatVariableDeclarationList(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*1*/var fun1 = function ( ) { /*2*/ var x = 'foo' , diff --git a/internal/fourslash/tests/gen/formatWithStatement_test.go b/internal/fourslash/tests/gen/formatWithStatement_test.go index 7ef56b55bc..5e8924c7de 100644 --- a/internal/fourslash/tests/gen/formatWithStatement_test.go +++ b/internal/fourslash/tests/gen/formatWithStatement_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormatWithStatement(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `with /*1*/(foo.bar) diff --git a/internal/fourslash/tests/gen/formatonkey01_test.go b/internal/fourslash/tests/gen/formatonkey01_test.go index 14b9d7a51c..bc930cf31c 100644 --- a/internal/fourslash/tests/gen/formatonkey01_test.go +++ b/internal/fourslash/tests/gen/formatonkey01_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormatonkey01(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `switch (1) { case 1: @@ -27,9 +22,5 @@ func TestFormatonkey01(t *testing.T) { f.MarkTestAsStradaServer() f.GoToMarker(t, "1") f.Insert(t, "}") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, ` }`) -======= - f.VerifyCurrentLineContentIs(t, " }") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formattingAfterChainedFatArrow_test.go b/internal/fourslash/tests/gen/formattingAfterChainedFatArrow_test.go index 4b67c9e840..a4bf96068a 100644 --- a/internal/fourslash/tests/gen/formattingAfterChainedFatArrow_test.go +++ b/internal/fourslash/tests/gen/formattingAfterChainedFatArrow_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingAfterChainedFatArrow(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `var x = n => p => { while (true) { diff --git a/internal/fourslash/tests/gen/formattingAfterMultiLineIfCondition_test.go b/internal/fourslash/tests/gen/formattingAfterMultiLineIfCondition_test.go index d066a9c4dc..5feb86a82f 100644 --- a/internal/fourslash/tests/gen/formattingAfterMultiLineIfCondition_test.go +++ b/internal/fourslash/tests/gen/formattingAfterMultiLineIfCondition_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormattingAfterMultiLineIfCondition(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - t.Skip() -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = ` var foo; if (foo && @@ -27,9 +22,5 @@ func TestFormattingAfterMultiLineIfCondition(t *testing.T) { f.GoToMarker(t, "") f.Insert(t, "}") f.GoToMarker(t, "comment") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, ` // This is a comment`) -======= - f.VerifyCurrentLineContentIs(t, " // This is a comment") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formattingAfterMultiLineString_test.go b/internal/fourslash/tests/gen/formattingAfterMultiLineString_test.go index 5170b3dc7a..4cdc79291f 100644 --- a/internal/fourslash/tests/gen/formattingAfterMultiLineString_test.go +++ b/internal/fourslash/tests/gen/formattingAfterMultiLineString_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormattingAfterMultiLineString(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class foo { stop() { @@ -27,9 +22,5 @@ func TestFormattingAfterMultiLineString(t *testing.T) { f.GoToMarker(t, "2") f.InsertLine(t, "") f.GoToMarker(t, "1") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, " var s = \"hello\\") -======= - f.VerifyCurrentLineContentIs(t, " var s = \"hello\\") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formattingArrayLiteral_test.go b/internal/fourslash/tests/gen/formattingArrayLiteral_test.go index 56c018a157..69e050a58b 100644 --- a/internal/fourslash/tests/gen/formattingArrayLiteral_test.go +++ b/internal/fourslash/tests/gen/formattingArrayLiteral_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingArrayLiteral(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*1*/x= []; y = [ diff --git a/internal/fourslash/tests/gen/formattingAwait_test.go b/internal/fourslash/tests/gen/formattingAwait_test.go index b1ed32e643..05b14c9dfc 100644 --- a/internal/fourslash/tests/gen/formattingAwait_test.go +++ b/internal/fourslash/tests/gen/formattingAwait_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingAwait(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `async function f() { for await (const x of g()) { diff --git a/internal/fourslash/tests/gen/formattingBlockInCaseClauses_test.go b/internal/fourslash/tests/gen/formattingBlockInCaseClauses_test.go index 4243a3894e..7e5a922c80 100644 --- a/internal/fourslash/tests/gen/formattingBlockInCaseClauses_test.go +++ b/internal/fourslash/tests/gen/formattingBlockInCaseClauses_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormattingBlockInCaseClauses(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `switch (1) { case 1: @@ -26,9 +21,5 @@ func TestFormattingBlockInCaseClauses(t *testing.T) { defer done() f.GoToMarker(t, "1") f.Insert(t, "}") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, ` }`) -======= - f.VerifyCurrentLineContentIs(t, " }") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formattingChainingMethods_test.go b/internal/fourslash/tests/gen/formattingChainingMethods_test.go index 387acb7a19..447cef098e 100644 --- a/internal/fourslash/tests/gen/formattingChainingMethods_test.go +++ b/internal/fourslash/tests/gen/formattingChainingMethods_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingChainingMethods(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = ` z$ = this.store.select(this.fake()) .ofType( diff --git a/internal/fourslash/tests/gen/formattingComma_test.go b/internal/fourslash/tests/gen/formattingComma_test.go index e65f55a890..68a3f2f1e8 100644 --- a/internal/fourslash/tests/gen/formattingComma_test.go +++ b/internal/fourslash/tests/gen/formattingComma_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingComma(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `var x = [1 , 2];/*x*/ var y = ( 1 , 2 );/*y*/ diff --git a/internal/fourslash/tests/gen/formattingCommentsBeforeErrors_test.go b/internal/fourslash/tests/gen/formattingCommentsBeforeErrors_test.go index 7de439c870..41d595bba8 100644 --- a/internal/fourslash/tests/gen/formattingCommentsBeforeErrors_test.go +++ b/internal/fourslash/tests/gen/formattingCommentsBeforeErrors_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormattingCommentsBeforeErrors(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `module A { interface B { @@ -34,9 +29,5 @@ func TestFormattingCommentsBeforeErrors(t *testing.T) { f.GoToMarker(t, "1") f.Insert(t, "\n") f.GoToMarker(t, "0") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, ` // d `) -======= - f.VerifyCurrentLineContentIs(t, " // d ") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formattingConditionalOperator_test.go b/internal/fourslash/tests/gen/formattingConditionalOperator_test.go index 2cf1809bb5..6e56deaeb7 100644 --- a/internal/fourslash/tests/gen/formattingConditionalOperator_test.go +++ b/internal/fourslash/tests/gen/formattingConditionalOperator_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingConditionalOperator(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `var x=true?1:2` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formattingConditionalTypes_test.go b/internal/fourslash/tests/gen/formattingConditionalTypes_test.go index 165aefd54c..602f1a3218 100644 --- a/internal/fourslash/tests/gen/formattingConditionalTypes_test.go +++ b/internal/fourslash/tests/gen/formattingConditionalTypes_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingConditionalTypes(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*L1*/type Diff1 = T extends U?never:T; /*L2*/type Diff2 = T extends U ? never : T;` diff --git a/internal/fourslash/tests/gen/formattingCrash_test.go b/internal/fourslash/tests/gen/formattingCrash_test.go index a0ae593602..0239dc1f36 100644 --- a/internal/fourslash/tests/gen/formattingCrash_test.go +++ b/internal/fourslash/tests/gen/formattingCrash_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingCrash(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/**/module Default{ }` diff --git a/internal/fourslash/tests/gen/formattingDecorators_test.go b/internal/fourslash/tests/gen/formattingDecorators_test.go index 5385c3e236..9f89e294bc 100644 --- a/internal/fourslash/tests/gen/formattingDecorators_test.go +++ b/internal/fourslash/tests/gen/formattingDecorators_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingDecorators(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*1*/ @ decorator1 /*2*/ @ decorator2 diff --git a/internal/fourslash/tests/gen/formattingDoubleLessThan_test.go b/internal/fourslash/tests/gen/formattingDoubleLessThan_test.go index 64bb47cf04..65ceac18cd 100644 --- a/internal/fourslash/tests/gen/formattingDoubleLessThan_test.go +++ b/internal/fourslash/tests/gen/formattingDoubleLessThan_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingDoubleLessThan(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*1*/if (foo < bar) {}` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formattingElseInsideAFunction_test.go b/internal/fourslash/tests/gen/formattingElseInsideAFunction_test.go index e508a91037..23f9cd1dc3 100644 --- a/internal/fourslash/tests/gen/formattingElseInsideAFunction_test.go +++ b/internal/fourslash/tests/gen/formattingElseInsideAFunction_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormattingElseInsideAFunction(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `var x = function() { if (true) { @@ -27,9 +22,5 @@ func TestFormattingElseInsideAFunction(t *testing.T) { f.GoToMarker(t, "2") f.InsertLine(t, "") f.GoToMarker(t, "1") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, ` } else {`) -======= - f.VerifyCurrentLineContentIs(t, " } else {") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go b/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go index 939eb5551a..2f559a90af 100644 --- a/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go +++ b/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go @@ -8,22 +8,13 @@ import ( ) func TestFormattingEqualsBeforeBracketInTypeAlias(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `type X = [number]/*1*/` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) defer done() f.GoToMarker(t, "1") f.Insert(t, ";") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, `type X = [number];`) -======= - f.VerifyCurrentLineContentIs(t, "type X = [number];") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go b/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go index 4e04e0efda..8ffc50de21 100644 --- a/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go +++ b/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormattingExpressionsInIfCondition(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `if (a === 1 || /*0*/b === 2 ||/*1*/ @@ -25,9 +20,5 @@ func TestFormattingExpressionsInIfCondition(t *testing.T) { f.GoToMarker(t, "1") f.Insert(t, "\n") f.GoToMarker(t, "0") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, ` b === 2 ||`) -======= - f.VerifyCurrentLineContentIs(t, " b === 2 ||") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formattingFatArrowFunctions_test.go b/internal/fourslash/tests/gen/formattingFatArrowFunctions_test.go index 5bd0a9771f..5290ab15a9 100644 --- a/internal/fourslash/tests/gen/formattingFatArrowFunctions_test.go +++ b/internal/fourslash/tests/gen/formattingFatArrowFunctions_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingFatArrowFunctions(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// valid ( ) => 1 ;/*1*/ diff --git a/internal/fourslash/tests/gen/formattingForIn_test.go b/internal/fourslash/tests/gen/formattingForIn_test.go index 8f6990677b..5b34c91a21 100644 --- a/internal/fourslash/tests/gen/formattingForIn_test.go +++ b/internal/fourslash/tests/gen/formattingForIn_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingForIn(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/**/for (var i in[] ) {}` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formattingForLoopSemicolons_test.go b/internal/fourslash/tests/gen/formattingForLoopSemicolons_test.go index 69bd077ce4..c7d0012e26 100644 --- a/internal/fourslash/tests/gen/formattingForLoopSemicolons_test.go +++ b/internal/fourslash/tests/gen/formattingForLoopSemicolons_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingForLoopSemicolons(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*1*/for (;;) { } /*2*/for (var x;x<0;x++) { } diff --git a/internal/fourslash/tests/gen/formattingForOfKeyword_test.go b/internal/fourslash/tests/gen/formattingForOfKeyword_test.go index 761ca0f182..7ec5dfb430 100644 --- a/internal/fourslash/tests/gen/formattingForOfKeyword_test.go +++ b/internal/fourslash/tests/gen/formattingForOfKeyword_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingForOfKeyword(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/**/for ([]of[]) { }` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formattingGlobalAugmentation1_test.go b/internal/fourslash/tests/gen/formattingGlobalAugmentation1_test.go index 2ce50a9fb0..7e1e193a6d 100644 --- a/internal/fourslash/tests/gen/formattingGlobalAugmentation1_test.go +++ b/internal/fourslash/tests/gen/formattingGlobalAugmentation1_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingGlobalAugmentation1(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*1*/declare global { }` diff --git a/internal/fourslash/tests/gen/formattingGlobalAugmentation2_test.go b/internal/fourslash/tests/gen/formattingGlobalAugmentation2_test.go index 8e483a18eb..3af90b8410 100644 --- a/internal/fourslash/tests/gen/formattingGlobalAugmentation2_test.go +++ b/internal/fourslash/tests/gen/formattingGlobalAugmentation2_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingGlobalAugmentation2(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - t.Skip() defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `declare module "A" { /*1*/ global { diff --git a/internal/fourslash/tests/gen/formattingHexLiteral_test.go b/internal/fourslash/tests/gen/formattingHexLiteral_test.go index bda553bd73..9e11c82b2c 100644 --- a/internal/fourslash/tests/gen/formattingHexLiteral_test.go +++ b/internal/fourslash/tests/gen/formattingHexLiteral_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingHexLiteral(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `var x = 0x1,y;` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go b/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go index 253c7f8cc8..8a2385d3a2 100644 --- a/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go +++ b/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormattingIfInElseBlock(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `if (true) { } @@ -26,9 +21,5 @@ else { defer done() f.GoToMarker(t, "1") f.Insert(t, "}") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, ` }`) -======= - f.VerifyCurrentLineContentIs(t, " }") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formattingIllegalImportClause_test.go b/internal/fourslash/tests/gen/formattingIllegalImportClause_test.go index 7baa2f3b27..fa5176983a 100644 --- a/internal/fourslash/tests/gen/formattingIllegalImportClause_test.go +++ b/internal/fourslash/tests/gen/formattingIllegalImportClause_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingIllegalImportClause(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `var expect = require('expect.js'); import React from 'react'/*1*/; diff --git a/internal/fourslash/tests/gen/formattingInComment_test.go b/internal/fourslash/tests/gen/formattingInComment_test.go index 809b01c58a..5860d83b2c 100644 --- a/internal/fourslash/tests/gen/formattingInComment_test.go +++ b/internal/fourslash/tests/gen/formattingInComment_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormattingInComment(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class A { foo( ); // /*1*/ @@ -24,15 +19,8 @@ function foo() { var x; } // /*2*/` defer done() f.GoToMarker(t, "1") f.Insert(t, ";") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, `foo( ); // ;`) f.GoToMarker(t, "2") f.Insert(t, "}") f.VerifyCurrentLineContent(t, `function foo() { var x; } // }`) -======= - f.VerifyCurrentLineContentIs(t, "foo( ); // ;") - f.GoToMarker(t, "2") - f.Insert(t, "}") - f.VerifyCurrentLineContentIs(t, "function foo() { var x; } // }") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formattingInDestructuring1_test.go b/internal/fourslash/tests/gen/formattingInDestructuring1_test.go index 16965cbe3c..9c3621c369 100644 --- a/internal/fourslash/tests/gen/formattingInDestructuring1_test.go +++ b/internal/fourslash/tests/gen/formattingInDestructuring1_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingInDestructuring1(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `interface let { } /*1*/var x: let []; diff --git a/internal/fourslash/tests/gen/formattingInDestructuring2_test.go b/internal/fourslash/tests/gen/formattingInDestructuring2_test.go index f6c4e44f74..a25ae54100 100644 --- a/internal/fourslash/tests/gen/formattingInDestructuring2_test.go +++ b/internal/fourslash/tests/gen/formattingInDestructuring2_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingInDestructuring2(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*1*/function drawText( { text = "", location: [x, y]= [0, 0], bold = false }) { // Draw text diff --git a/internal/fourslash/tests/gen/formattingInDestructuring3_test.go b/internal/fourslash/tests/gen/formattingInDestructuring3_test.go index b6fc116982..c40d59c4e3 100644 --- a/internal/fourslash/tests/gen/formattingInDestructuring3_test.go +++ b/internal/fourslash/tests/gen/formattingInDestructuring3_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingInDestructuring3(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*1*/const { /*2*/ a, diff --git a/internal/fourslash/tests/gen/formattingInDestructuring4_test.go b/internal/fourslash/tests/gen/formattingInDestructuring4_test.go index a9a5a33383..f3a8a1c12d 100644 --- a/internal/fourslash/tests/gen/formattingInDestructuring4_test.go +++ b/internal/fourslash/tests/gen/formattingInDestructuring4_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingInDestructuring4(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/*1*/const { /*2*/ a, diff --git a/internal/fourslash/tests/gen/formattingInDestructuring5_test.go b/internal/fourslash/tests/gen/formattingInDestructuring5_test.go index 47073485cb..8f1ad571c6 100644 --- a/internal/fourslash/tests/gen/formattingInDestructuring5_test.go +++ b/internal/fourslash/tests/gen/formattingInDestructuring5_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingInDestructuring5(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `let a, b; /*1*/if (false)[a, b] = [1, 2]; diff --git a/internal/fourslash/tests/gen/formattingInExpressionsInTsx_test.go b/internal/fourslash/tests/gen/formattingInExpressionsInTsx_test.go index a25364b598..1c2053acd0 100644 --- a/internal/fourslash/tests/gen/formattingInExpressionsInTsx_test.go +++ b/internal/fourslash/tests/gen/formattingInExpressionsInTsx_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormattingInExpressionsInTsx(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - t.Skip() -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @Filename: test.tsx import * as React from "react"; @@ -28,9 +23,5 @@ return true/*1*/ defer done() f.GoToMarker(t, "1") f.Insert(t, ";") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, ` return true;`) -======= - f.VerifyCurrentLineContentIs(t, " return true;") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formattingInMultilineComments_test.go b/internal/fourslash/tests/gen/formattingInMultilineComments_test.go index 70150ac2a6..03e211886e 100644 --- a/internal/fourslash/tests/gen/formattingInMultilineComments_test.go +++ b/internal/fourslash/tests/gen/formattingInMultilineComments_test.go @@ -8,13 +8,8 @@ import ( ) func TestFormattingInMultilineComments(t *testing.T) { -<<<<<<< HEAD - t.Parallel() - -======= fourslash.SkipIfFailing(t) t.Parallel() ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `var x = function() { if (true) { @@ -27,9 +22,5 @@ func TestFormattingInMultilineComments(t *testing.T) { f.GoToMarker(t, "2") f.InsertLine(t, "") f.GoToMarker(t, "1") -<<<<<<< HEAD f.VerifyCurrentLineContent(t, ` } else {`) -======= - f.VerifyCurrentLineContentIs(t, " } else {") ->>>>>>> 20bf4fc90d3d38016f07fda1fb972eedc715bb02 } diff --git a/internal/fourslash/tests/gen/formattingJsxTexts1_test.go b/internal/fourslash/tests/gen/formattingJsxTexts1_test.go index b97d8b621d..04e56f0879 100644 --- a/internal/fourslash/tests/gen/formattingJsxTexts1_test.go +++ b/internal/fourslash/tests/gen/formattingJsxTexts1_test.go @@ -8,8 +8,8 @@ import ( ) func TestFormattingJsxTexts1(t *testing.T) { + fourslash.SkipIfFailing(t) t.Parallel() - defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `//@Filename: file.tsx