diff --git a/internal/execute/tsc.go b/internal/execute/tsc.go index e314f4433f..281fb43ddb 100644 --- a/internal/execute/tsc.go +++ b/internal/execute/tsc.go @@ -16,6 +16,7 @@ import ( "github.com/microsoft/typescript-go/internal/format" "github.com/microsoft/typescript-go/internal/jsonutil" "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" @@ -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..1a8f3ff972 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 { @@ -267,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) } } @@ -302,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 } @@ -968,7 +972,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 +1084,7 @@ type dynamicIndenter struct { indentation int delta int - options *FormatCodeSettings + options *lsutil.FormatCodeSettings sourceFile *ast.SourceFile } diff --git a/internal/fourslash/_scripts/convertFourslash.mts b/internal/fourslash/_scripts/convertFourslash.mts index d958369d81..8e391e40fb 100644 --- a/internal/fourslash/_scripts/convertFourslash.mts +++ b/internal/fourslash/_scripts/convertFourslash.mts @@ -181,6 +181,12 @@ function parseFourslashStatement(statement: ts.Statement): Cmd[] | undefined { case "importFixModuleSpecifiers": // `verify.importFixModuleSpecifiers(...)` return parseImportFixModuleSpecifiersArgs(callExpression.arguments); + case "currentLineContentIs": + case "currentFileContentIs": + case "indentationIs": + case "indentationAtPositionIs": + case "textAtCaretIs": + return parseCurrentContentIsArgs(func.text, callExpression.arguments); case "quickInfoAt": case "quickInfoExists": case "quickInfoIs": @@ -273,6 +279,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()}`); @@ -355,6 +364,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 + "`"; @@ -366,6 +432,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": { @@ -2776,6 +2860,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; @@ -2906,7 +3000,9 @@ type Cmd = | VerifyNoSignatureHelpForTriggerReasonCmd | VerifyBaselineCallHierarchy | GoToCmd + | FormatCmd | EditCmd + | VerifyContentCmd | VerifyQuickInfoCmd | VerifyBaselineRenameCmd | VerifyRenameInfoCmd @@ -3201,6 +3297,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/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 be20094672..e586cb22f1 100644 --- a/internal/fourslash/_scripts/failingTests.txt +++ b/internal/fourslash/_scripts/failingTests.txt @@ -37,6 +37,7 @@ TestAutoImportProvider_pnpm TestAutoImportProvider_wildcardExports1 TestAutoImportProvider_wildcardExports2 TestAutoImportProvider_wildcardExports3 +TestAutoImportProvider1 TestAutoImportProvider4 TestAutoImportProvider9 TestAutoImportSortCaseSensitivity1 @@ -241,7 +242,6 @@ TestCompletionsWithDeprecatedTag10 TestCompletionWithConditionalOperatorMissingColon TestConstEnumQuickInfoAndCompletionList TestConstQuickInfoAndCompletionList -TestConstructorBraceFormatting TestContextuallyTypedFunctionExpressionGeneric1 TestContextualTypingOfGenericCallSignatures2 TestCrossFileQuickInfoExportedTypeDoesNotUseImportType @@ -257,27 +257,82 @@ TestFindAllRefs_importType_js2 TestFindAllRefs_importType_js3 TestFindReferencesBindingPatternInJsdocNoCrash1 TestFindReferencesBindingPatternInJsdocNoCrash2 -TestFormatAfterWhitespace -TestFormatAnyTypeLiteral -TestFormatEmptyBlock +TestForceIndentAfterNewLineInsert +TestFormat01 +TestFormatAfterObjectLiteral +TestFormatArrayLiteralExpression +TestFormatAsyncClassMethod1 +TestFormatAsyncClassMethod2 +TestFormatColonAndQMark +TestFormatComments +TestFormatConflictDiff3Marker1 +TestFormatConflictMarker1 +TestFormatDebuggerStatement +TestFormatDocumentPreserveTrailingWhitespace +TestFormatDocumentWithJSDoc +TestFormatDocumentWithTrivia +TestFormatDotAfterNumber TestFormatEmptyParamList -TestFormatonkey01 +TestFormatIfTryCatchBlocks +TestFormatIfWithEmptyCondition +TestFormatImplicitModule +TestFormatMultipleFunctionArguments +TestFormatNoSpaceAfterTemplateHeadAndMiddle +TestFormatObjectBindingPattern TestFormatOnSemiColonAfterBreak +TestFormatRemoveNewLineAfterOpenBrace +TestFormatSpaceAfterImplementsExtends +TestFormatSpaceAfterTemplateHeadAndMiddle +TestFormatSpaceBetweenFunctionAndArrayIndex TestFormattingAfterMultiLineIfCondition -TestFormattingBlockInCaseClauses -TestFormattingEqualsBeforeBracketInTypeAlias -TestFormattingIfInElseBlock +TestFormattingAwait +TestFormattingChainingMethods +TestFormattingDecorators +TestFormattingDoubleLessThan +TestFormattingForIn +TestFormattingForLoopSemicolons +TestFormattingForOfKeyword +TestFormattingGlobalAugmentation2 TestFormattingInExpressionsInTsx -TestFormattingOfChainedLambda -TestFormattingOnCloseBrace +TestFormattingJsxTexts2 +TestFormattingJsxTexts3 +TestFormattingJsxTexts4 +TestFormattingMappedType +TestFormattingMultilineCommentsWithTabs1 +TestFormattingNestedScopes +TestFormattingNonNullAssertionOperator +TestFormattingObjectLiteral +TestFormattingObjectLiteralOpenCurlyNewline +TestFormattingObjectLiteralOpenCurlyNewlineAssignment +TestFormattingObjectLiteralOpenCurlyNewlineTyping +TestFormattingObjectLiteralOpenCurlySingleLine +TestFormattingOfExportDefault +TestFormattingOnClasses +TestFormattingOnClosingBracket +TestFormattingOnDocumentReadyFunction TestFormattingOnDoWhileNoSemicolon -TestFormattingOnEnter +TestFormattingOnEmptyInterfaceLiteral +TestFormattingOnInvalidCodes +TestFormattingOnModuleIndentation TestFormattingOnNestedDoWhileByEnter -TestFormattingOnSemiColon +TestFormattingOnObjectLiteral +TestFormattingOnSingleLineBlocks +TestFormattingOnStatementsWithNoSemicolon +TestFormattingOnTabAfterCloseCurly +TestFormattingOnVariety +TestFormattingReplaceTabsWithSpaces TestFormattingSpaceAfterCommaBeforeOpenParen +TestFormattingSpaceBeforeFunctionParen +TestFormattingSpaceBetweenParent +TestFormattingSpacesAfterConstructor TestFormattingTemplates -TestFormattingWithMultilineComments -TestFunctionTypeFormatting +TestFormattingVoid +TestFormatTryFinally +TestFormatTsxClosingAfterJsxText +TestFormatVariableDeclarationList +TestFormatWithStatement +TestFunctionIndentation +TestFunctionTypePredicateFormatting TestFunduleWithRecursiveReference TestGenericCombinators3 TestGenericCombinatorWithConstraints1 @@ -285,6 +340,7 @@ TestGenericFunctionWithGenericParams1 TestGenericInterfacePropertyInference1 TestGenericInterfacePropertyInference2 TestGenericInterfacesWithConstraints1 +TestGenericsFormattingMultiline TestGenericTypeWithMultipleBases1MultiFile TestGetJavaScriptCompletions10 TestGetJavaScriptCompletions12 @@ -326,6 +382,7 @@ TestImportCompletionsPackageJsonImportsPattern2 TestImportFixesGlobalTypingsCache TestImportMetaCompletionDetails TestImportNameCodeFix_avoidRelativeNodeModules +TestImportNameCodeFix_externalNonRelative1 TestImportNameCodeFix_fileWithNoTrailingNewline TestImportNameCodeFix_HeaderComment1 TestImportNameCodeFix_HeaderComment2 @@ -369,6 +426,7 @@ TestImportTypeCompletions6 TestImportTypeCompletions7 TestImportTypeCompletions8 TestImportTypeCompletions9 +TestIndentationInJsx3 TestIndexerReturnTypes1 TestIndirectClassInstantiation TestInstanceTypesForGenericType1 @@ -417,6 +475,7 @@ TestMemberListInReopenedEnum TestMemberListInWithBlock TestMemberListOfExportedClass TestMemberListOnContextualThis +TestMultilineCommentBeforeOpenBrace TestMultiModuleFundule TestNgProxy1 TestNgProxy4 @@ -424,10 +483,10 @@ TestNodeModulesImportCompletions1 TestNoQuickInfoForLabel TestNoQuickInfoInWhitespace TestNumericPropertyNames +TestOptionalPropertyFormatting TestOverloadQuickInfo TestParameterWithDestructuring TestParameterWithNestedDestructuring -TestPaste TestPathCompletionsAllowModuleAugmentationExtensions TestPathCompletionsAllowTsExtensions TestPathCompletionsPackageJsonExportsBundlerNoNodeCondition @@ -597,11 +656,9 @@ TestRenameFromNodeModulesDep4 TestRenamePrivateFields TestReverseMappedTypeQuickInfo TestSelfReferencedExternalModule -TestSemicolonFormatting -TestSemicolonFormattingAfterArrayLiteral TestSemicolonFormattingNestedStatements TestSignatureHelpCallExpressionJs -TestSpaceAfterConstructor +TestSpaceAfterReturn TestStringCompletionsImportOrExportSpecifier TestStringCompletionsVsEscaping TestSymbolCompletionLowerPriority @@ -626,7 +683,6 @@ TestTsxQuickInfo7 TestTypeCheckAfterResolve TestTypeOperatorNodeBuilding TestUnclosedStringLiteralAutoformating -TestWhiteSpaceBeforeReturnTypeFormatting TestWhiteSpaceTrimming TestWhiteSpaceTrimming2 TestWhiteSpaceTrimming4 diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index 488c0beff8..6e957fc615 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()) @@ -612,15 +637,23 @@ func sendRequest[Params, Resp any](t *testing.T, f *FourslashTest, info lsproto. 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) - } - resp := resMsg.AsResponse() - if resp.Error != nil { - t.Fatalf(prefix+"%s request returned error: %s", info.Method, resp.Error.String()) - } - if !resultOk { - t.Fatalf(prefix+"Unexpected %s response type: %T", info.Method, resp.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) + } + resp := resMsg.AsResponse() + if resp.Error != nil { + t.Fatalf(prefix+"%s request returned error: %s", info.Method, resp.Error.String()) + } + if !resultOk { + t.Fatalf(prefix+"Unexpected %s response type: %T", info.Method, resp.Result) + } } return result } @@ -642,6 +675,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 @@ -855,6 +895,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, @@ -1348,13 +1429,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, @@ -1418,6 +1500,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 @@ -1433,9 +1516,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)) } } @@ -2525,11 +2606,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") } @@ -2564,6 +2647,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? } @@ -2607,20 +2707,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) { @@ -2630,29 +2748,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/autoImportCompletion_test.go b/internal/fourslash/tests/autoImportCompletion_test.go index 7f94f697a2..5777a3253e 100644 --- a/internal/fourslash/tests/autoImportCompletion_test.go +++ b/internal/fourslash/tests/autoImportCompletion_test.go @@ -44,8 +44,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/fourslash/tests/gen/asOperatorFormatting_test.go b/internal/fourslash/tests/gen/asOperatorFormatting_test.go new file mode 100644 index 0000000000..e6ccb65428 --- /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) { + 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) + 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 index f5ea5fad6c..f466d337cf 100644 --- a/internal/fourslash/tests/gen/autoFormattingOnPasting_test.go +++ b/internal/fourslash/tests/gen/autoFormattingOnPasting_test.go @@ -18,5 +18,10 @@ func TestAutoFormattingOnPasting(t *testing.T) { defer done() f.GoToMarker(t, "") f.Paste(t, " class TestClass{\nprivate foo;\npublic testMethod( )\n{}\n}") - f.VerifyCurrentFileContentIs(t, "module TestModule {\n class TestClass {\n private foo;\n public 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..818e62263e --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..48721aac25 --- /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) { + 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": "*" } } +// @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..94f4ccb504 --- /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) { + 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" } } +// @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..4633833b6a --- /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) { + 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" } } +// @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 index e6d3907730..96fa8fb1aa 100644 --- a/internal/fourslash/tests/gen/chainedFatArrowFormatting_test.go +++ b/internal/fourslash/tests/gen/chainedFatArrowFormatting_test.go @@ -16,5 +16,5 @@ func TestChainedFatArrowFormatting(t *testing.T) { defer done() f.GoToMarker(t, "") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "var fn = () => () => null;") + 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..7de08dd7f2 --- /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) { + fourslash.SkipIfFailing(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..a9256e0873 --- /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) { + 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" } } +// @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..57ea302a81 --- /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) { + 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 } } +// @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..e66edd9dff --- /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) { + fourslash.SkipIfFailing(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 index e3dabd18cf..0ee2d43fe7 100644 --- a/internal/fourslash/tests/gen/constructorBraceFormatting_test.go +++ b/internal/fourslash/tests/gen/constructorBraceFormatting_test.go @@ -19,5 +19,5 @@ func TestConstructorBraceFormatting(t *testing.T) { f.GoToMarker(t, "") f.Insert(t, "}") f.GoToMarker(t, "target") - f.VerifyCurrentLineContentIs(t, " constructor() { }") + 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..bd809091bc --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..e71a216a51 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..904b9ffd33 --- /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) { + fourslash.SkipIfFailing(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..20f458ecd2 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..5a4afd8efe --- /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) { + 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) + 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 index 9fb04b1f28..eace515298 100644 --- a/internal/fourslash/tests/gen/formatAfterWhitespace_test.go +++ b/internal/fourslash/tests/gen/formatAfterWhitespace_test.go @@ -20,5 +20,10 @@ func TestFormatAfterWhitespace(t *testing.T) { defer done() f.GoToMarker(t, "1") f.InsertLine(t, "") - f.VerifyCurrentFileContentIs(t, "function foo()\n{\n var bar;\n\n\n}") + 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 index 90ccad2bbc..e12670e1aa 100644 --- a/internal/fourslash/tests/gen/formatAnyTypeLiteral_test.go +++ b/internal/fourslash/tests/gen/formatAnyTypeLiteral_test.go @@ -18,5 +18,5 @@ func TestFormatAnyTypeLiteral(t *testing.T) { f.GoToMarker(t, "") f.Insert(t, "}") f.GoToMarker(t, "objLit") - f.VerifyCurrentLineContentIs(t, "function foo(x: {}) {") + 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..49631f1609 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..9edc5e806d --- /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) { + 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) + 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..a026f97985 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..b2d9ac1659 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..6ec6975890 --- /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) { + fourslash.SkipIfFailing(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..efa2a36a0c --- /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) { + 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; +/*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..5ed280e4e2 --- /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) { + fourslash.SkipIfFailing(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..9fec50c5c7 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..9fed00c20d --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..27b21a8712 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..8a5c279585 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..bedd66171c --- /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) { + fourslash.SkipIfFailing(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..8a97d2c4e7 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..7453579cd9 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..fc991cff8c --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..4537afa63e --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..718564ff1f --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index 680ba862b8..784e999417 100644 --- a/internal/fourslash/tests/gen/formatEmptyBlock_test.go +++ b/internal/fourslash/tests/gen/formatEmptyBlock_test.go @@ -17,5 +17,5 @@ func TestFormatEmptyBlock(t *testing.T) { f.GoToEOF(t) f.Insert(t, "\n") f.GoToBOF(t) - f.VerifyCurrentLineContentIs(t, "{ }") + f.VerifyCurrentLineContent(t, `{ }`) } diff --git a/internal/fourslash/tests/gen/formatEmptyParamList_test.go b/internal/fourslash/tests/gen/formatEmptyParamList_test.go index a34ce903b0..d58961567d 100644 --- a/internal/fourslash/tests/gen/formatEmptyParamList_test.go +++ b/internal/fourslash/tests/gen/formatEmptyParamList_test.go @@ -16,5 +16,5 @@ func TestFormatEmptyParamList(t *testing.T) { defer done() f.GoToMarker(t, "1") f.Insert(t, "}") - f.VerifyCurrentLineContentIs(t, "function f(f: function) { }") + 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..5cf5506b24 --- /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) { + 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) + 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..2d9089ddc0 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..cf63ca3b08 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..3628d1a916 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..02e6fc86cb --- /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) { + fourslash.SkipIfFailing(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 index 35c04b0d16..b0c2f56c88 100644 --- a/internal/fourslash/tests/gen/formatInTryCatchFinally_test.go +++ b/internal/fourslash/tests/gen/formatInTryCatchFinally_test.go @@ -22,5 +22,5 @@ catch (e) defer done() f.GoToMarker(t, "1") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, " var x = 1;") + 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..3418e29e12 --- /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) { + fourslash.SkipIfFailing(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..f8d02dca47 --- /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) { + fourslash.SkipIfFailing(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..d632e08bfd --- /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) { + fourslash.SkipIfFailing(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..bc72769c95 --- /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) { + fourslash.SkipIfFailing(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..b071986d17 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..9ad97a5391 --- /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) { + fourslash.SkipIfFailing(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..3577e26b8f --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..1e4c1ba1ad --- /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) { + 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) + 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..537842db7d --- /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) { + 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) + 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..870d0d1db9 --- /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) { + 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) + 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..8cfbd0ac13 --- /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) { + 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) + 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..fe85e96d37 --- /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) { + 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) + 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..fda3568204 --- /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) { + 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) + 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..b3613ae2e7 --- /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) { + 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) + 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..de8a95b077 --- /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) { + fourslash.SkipIfFailing(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..1eeebb217e --- /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) { + 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) + 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..268e63a914 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index 30e88d85d5..ae6164e315 100644 --- a/internal/fourslash/tests/gen/formatOnEnterFunctionDeclaration_test.go +++ b/internal/fourslash/tests/gen/formatOnEnterFunctionDeclaration_test.go @@ -17,5 +17,5 @@ func TestFormatOnEnterFunctionDeclaration(t *testing.T) { f.GoToMarker(t, "1") f.InsertLine(t, "") f.GoToMarker(t, "0") - f.VerifyCurrentLineContentIs(t, "function listAPIFiles(path: string): string[] {") + 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 index 756906b43d..559a6e81f3 100644 --- a/internal/fourslash/tests/gen/formatOnEnterInComment_test.go +++ b/internal/fourslash/tests/gen/formatOnEnterInComment_test.go @@ -18,5 +18,8 @@ func TestFormatOnEnterInComment(t *testing.T) { defer done() f.GoToMarker(t, "1") f.InsertLine(t, "") - f.VerifyCurrentFileContentIs(t, " /**\n * \n\n */") + 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..ea8f946898 --- /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) { + fourslash.SkipIfFailing(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..4da4941b62 --- /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) { + fourslash.SkipIfFailing(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 index 0d9c56b074..86f822dc6b 100644 --- a/internal/fourslash/tests/gen/formatOnSemiColonAfterBreak_test.go +++ b/internal/fourslash/tests/gen/formatOnSemiColonAfterBreak_test.go @@ -18,5 +18,5 @@ break/**/ defer done() f.GoToMarker(t, "") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, " break;") + 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..f7ee996df9 --- /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) { + fourslash.SkipIfFailing(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..2103e0c03e --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..fe1256d3e6 --- /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) { + fourslash.SkipIfFailing(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..12fe648166 --- /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) { + 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[]; +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..a521d69286 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..64d6aef9db --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..a2dc12b44a --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..672cad19c9 --- /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) { + fourslash.SkipIfFailing(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..813eb7481a --- /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) { + fourslash.SkipIfFailing(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..0b6db74e71 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..8317ee2312 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..9e25f2ab9b --- /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) { + fourslash.SkipIfFailing(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..543adf277f --- /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) { + fourslash.SkipIfFailing(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..da3f75abbd --- /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) { + fourslash.SkipIfFailing(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..99b364b3ed --- /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) { + fourslash.SkipIfFailing(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..d3562372af --- /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) { + fourslash.SkipIfFailing(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..822ade1f0d --- /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) { + 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) + 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..cffd0764f6 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..5e8924c7de --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index 8938a52a0d..bc930cf31c 100644 --- a/internal/fourslash/tests/gen/formatonkey01_test.go +++ b/internal/fourslash/tests/gen/formatonkey01_test.go @@ -22,5 +22,5 @@ func TestFormatonkey01(t *testing.T) { f.MarkTestAsStradaServer() f.GoToMarker(t, "1") f.Insert(t, "}") - f.VerifyCurrentLineContentIs(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..a4bf96068a --- /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) { + fourslash.SkipIfFailing(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 index 2de681b773..5feb86a82f 100644 --- a/internal/fourslash/tests/gen/formattingAfterMultiLineIfCondition_test.go +++ b/internal/fourslash/tests/gen/formattingAfterMultiLineIfCondition_test.go @@ -22,5 +22,5 @@ func TestFormattingAfterMultiLineIfCondition(t *testing.T) { f.GoToMarker(t, "") f.Insert(t, "}") f.GoToMarker(t, "comment") - f.VerifyCurrentLineContentIs(t, " // This is a 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 index a816d92e4a..4cdc79291f 100644 --- a/internal/fourslash/tests/gen/formattingAfterMultiLineString_test.go +++ b/internal/fourslash/tests/gen/formattingAfterMultiLineString_test.go @@ -22,5 +22,5 @@ func TestFormattingAfterMultiLineString(t *testing.T) { f.GoToMarker(t, "2") f.InsertLine(t, "") f.GoToMarker(t, "1") - f.VerifyCurrentLineContentIs(t, " var s = \"hello\\") + 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..69e050a58b --- /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) { + fourslash.SkipIfFailing(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..05b14c9dfc --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index 7afd345d5f..7e5a922c80 100644 --- a/internal/fourslash/tests/gen/formattingBlockInCaseClauses_test.go +++ b/internal/fourslash/tests/gen/formattingBlockInCaseClauses_test.go @@ -21,5 +21,5 @@ func TestFormattingBlockInCaseClauses(t *testing.T) { defer done() f.GoToMarker(t, "1") f.Insert(t, "}") - f.VerifyCurrentLineContentIs(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..447cef098e --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..68a3f2f1e8 --- /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) { + 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*/ +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 index 5019bd1617..41d595bba8 100644 --- a/internal/fourslash/tests/gen/formattingCommentsBeforeErrors_test.go +++ b/internal/fourslash/tests/gen/formattingCommentsBeforeErrors_test.go @@ -29,5 +29,5 @@ func TestFormattingCommentsBeforeErrors(t *testing.T) { f.GoToMarker(t, "1") f.Insert(t, "\n") f.GoToMarker(t, "0") - f.VerifyCurrentLineContentIs(t, " // d ") + 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..6e56deaeb7 --- /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) { + 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) + 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..602f1a3218 --- /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) { + 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;` + 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..0239dc1f36 --- /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) { + fourslash.SkipIfFailing(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..9f89e294bc --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..65ceac18cd --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index 88a31e64c0..23f9cd1dc3 100644 --- a/internal/fourslash/tests/gen/formattingElseInsideAFunction_test.go +++ b/internal/fourslash/tests/gen/formattingElseInsideAFunction_test.go @@ -22,5 +22,5 @@ func TestFormattingElseInsideAFunction(t *testing.T) { f.GoToMarker(t, "2") f.InsertLine(t, "") f.GoToMarker(t, "1") - f.VerifyCurrentLineContentIs(t, " } else {") + f.VerifyCurrentLineContent(t, ` } else {`) } diff --git a/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go b/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go index 34fa01e643..2f559a90af 100644 --- a/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go +++ b/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go @@ -16,5 +16,5 @@ func TestFormattingEqualsBeforeBracketInTypeAlias(t *testing.T) { defer done() f.GoToMarker(t, "1") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "type X = [number];") + f.VerifyCurrentLineContent(t, `type X = [number];`) } diff --git a/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go b/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go index 09d0db97f9..8ffc50de21 100644 --- a/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go +++ b/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go @@ -20,5 +20,5 @@ func TestFormattingExpressionsInIfCondition(t *testing.T) { f.GoToMarker(t, "1") f.Insert(t, "\n") f.GoToMarker(t, "0") - f.VerifyCurrentLineContentIs(t, " b === 2 ||") + 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..5290ab15a9 --- /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) { + fourslash.SkipIfFailing(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..5b34c91a21 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..c7d0012e26 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..7ec5dfb430 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..7e1e193a6d --- /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) { + fourslash.SkipIfFailing(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..3af90b8410 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..9e11c82b2c --- /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) { + 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) + defer done() + f.FormatDocument(t, "") +} diff --git a/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go b/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go index 9afe6978f4..8a2385d3a2 100644 --- a/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go +++ b/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go @@ -21,5 +21,5 @@ else { defer done() f.GoToMarker(t, "1") f.Insert(t, "}") - f.VerifyCurrentLineContentIs(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..fa5176983a --- /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) { + 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*/; +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 index 13394eeb4c..5860d83b2c 100644 --- a/internal/fourslash/tests/gen/formattingInComment_test.go +++ b/internal/fourslash/tests/gen/formattingInComment_test.go @@ -19,8 +19,8 @@ function foo() { var x; } // /*2*/` defer done() f.GoToMarker(t, "1") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "foo( ); // ;") + f.VerifyCurrentLineContent(t, `foo( ); // ;`) f.GoToMarker(t, "2") f.Insert(t, "}") - f.VerifyCurrentLineContentIs(t, "function foo() { var x; } // }") + 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..9c3621c369 --- /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) { + fourslash.SkipIfFailing(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..a25ae54100 --- /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) { + 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 +}` + 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..c40d59c4e3 --- /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) { + fourslash.SkipIfFailing(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..f3a8a1c12d --- /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) { + fourslash.SkipIfFailing(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..8f1ad571c6 --- /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) { + 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]; +/*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 index 40fd426ee2..1c2053acd0 100644 --- a/internal/fourslash/tests/gen/formattingInExpressionsInTsx_test.go +++ b/internal/fourslash/tests/gen/formattingInExpressionsInTsx_test.go @@ -23,5 +23,5 @@ return true/*1*/ defer done() f.GoToMarker(t, "1") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, " return true;") + f.VerifyCurrentLineContent(t, ` return true;`) } diff --git a/internal/fourslash/tests/gen/formattingInMultilineComments_test.go b/internal/fourslash/tests/gen/formattingInMultilineComments_test.go index 63be023f80..03e211886e 100644 --- a/internal/fourslash/tests/gen/formattingInMultilineComments_test.go +++ b/internal/fourslash/tests/gen/formattingInMultilineComments_test.go @@ -22,5 +22,5 @@ func TestFormattingInMultilineComments(t *testing.T) { f.GoToMarker(t, "2") f.InsertLine(t, "") f.GoToMarker(t, "1") - f.VerifyCurrentLineContentIs(t, " } else {") + 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..04e56f0879 --- /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) { + fourslash.SkipIfFailing(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..5171df59b9 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..c763bb199f --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..704abc9dcd --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index 9216fc7db2..940a07bedc 100644 --- a/internal/fourslash/tests/gen/formattingKeywordAsIdentifier_test.go +++ b/internal/fourslash/tests/gen/formattingKeywordAsIdentifier_test.go @@ -16,5 +16,5 @@ func TestFormattingKeywordAsIdentifier(t *testing.T) { defer done() f.GoToMarker(t, "1") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "declare var module;") + 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..ad69d8909e --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..8610b2286d --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..f410d1de9e --- /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) { + fourslash.SkipIfFailing(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..4d2f6ba278 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..f291660f90 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..b90d33b2b2 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..bcf54290d0 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..f61b865ad1 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..d3f20b958c --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..628c01e34b --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index dcfdda9753..bdaa4baa20 100644 --- a/internal/fourslash/tests/gen/formattingOfChainedLambda_test.go +++ b/internal/fourslash/tests/gen/formattingOfChainedLambda_test.go @@ -16,5 +16,5 @@ func TestFormattingOfChainedLambda(t *testing.T) { defer done() f.GoToMarker(t, "") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "var fn = (x: string) => () => alert(x);") + 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..0cc8510e51 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..91361fac5d --- /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) { + fourslash.SkipIfFailing(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..77502807ff --- /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) { + fourslash.SkipIfFailing(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..a15681efd1 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index e4be161483..561a42387f 100644 --- a/internal/fourslash/tests/gen/formattingOnCloseBrace_test.go +++ b/internal/fourslash/tests/gen/formattingOnCloseBrace_test.go @@ -18,5 +18,5 @@ func TestFormattingOnCloseBrace(t *testing.T) { f.GoToMarker(t, "") f.Insert(t, "}") f.GoToBOF(t) - f.VerifyCurrentLineContentIs(t, "class foo {") + 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..76f8d1da81 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..ac9a341b0c --- /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) { + fourslash.SkipIfFailing(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..635b80cb8c --- /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) { + fourslash.SkipIfFailing(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 index 56c597dee5..8eff733cba 100644 --- a/internal/fourslash/tests/gen/formattingOnDoWhileNoSemicolon_test.go +++ b/internal/fourslash/tests/gen/formattingOnDoWhileNoSemicolon_test.go @@ -19,13 +19,13 @@ func TestFormattingOnDoWhileNoSemicolon(t *testing.T) { defer done() f.GoToMarker(t, "1") f.Insert(t, "\n") - f.VerifyCurrentLineContentIs(t, "while (1 !== 1)") + f.VerifyCurrentLineContent(t, `while (1 !== 1)`) f.GoToMarker(t, "2") - f.VerifyCurrentLineContentIs(t, "do {") + f.VerifyCurrentLineContent(t, `do {`) f.GoToMarker(t, "3") - f.VerifyCurrentLineContentIs(t, " for (var i = 0; i < 10; i++)") + f.VerifyCurrentLineContent(t, ` for (var i = 0; i < 10; i++)`) f.GoToMarker(t, "4") - f.VerifyCurrentLineContentIs(t, " i -= 2") + f.VerifyCurrentLineContent(t, ` i -= 2`) f.GoToMarker(t, "5") - f.VerifyCurrentLineContentIs(t, "}") + 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..fa87ae2abc --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..122c063030 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index 273bb0ca2e..80930fa1bc 100644 --- a/internal/fourslash/tests/gen/formattingOnEnterInComments_test.go +++ b/internal/fourslash/tests/gen/formattingOnEnterInComments_test.go @@ -22,5 +22,5 @@ func TestFormattingOnEnterInComments(t *testing.T) { f.GoToMarker(t, "1") f.InsertLine(t, "") f.GoToMarker(t, "2") - f.VerifyCurrentLineContentIs(t, " }") + f.VerifyCurrentLineContent(t, ` }`) } diff --git a/internal/fourslash/tests/gen/formattingOnEnterInStrings_test.go b/internal/fourslash/tests/gen/formattingOnEnterInStrings_test.go index aab767f005..8b6db9b2d3 100644 --- a/internal/fourslash/tests/gen/formattingOnEnterInStrings_test.go +++ b/internal/fourslash/tests/gen/formattingOnEnterInStrings_test.go @@ -18,5 +18,5 @@ func TestFormattingOnEnterInStrings(t *testing.T) { f.InsertLine(t, "") f.InsertLine(t, "") f.GoToMarker(t, "1") - f.VerifyCurrentLineContentIs(t, "var x = \"unclosed string literal\\") + 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 index bc7f38d6c3..3c8fe2da60 100644 --- a/internal/fourslash/tests/gen/formattingOnEnter_test.go +++ b/internal/fourslash/tests/gen/formattingOnEnter_test.go @@ -18,5 +18,8 @@ class bar {/**/ } defer done() f.GoToMarker(t, "") f.InsertLine(t, "") - f.VerifyCurrentFileContentIs(t, "class foo { }\nclass bar {\n}\n// new line here") + 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..ee802994bd --- /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) { + fourslash.SkipIfFailing(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..d32fdb1063 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..972f734e45 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index db2068ecd0..c49e67813a 100644 --- a/internal/fourslash/tests/gen/formattingOnNestedDoWhileByEnter_test.go +++ b/internal/fourslash/tests/gen/formattingOnNestedDoWhileByEnter_test.go @@ -21,17 +21,17 @@ func TestFormattingOnNestedDoWhileByEnter(t *testing.T) { defer done() f.GoToMarker(t, "1") f.Insert(t, "\n") - f.VerifyCurrentLineContentIs(t, " {") + f.VerifyCurrentLineContent(t, ` {`) f.GoToMarker(t, "2") - f.VerifyCurrentLineContentIs(t, "do{") + f.VerifyCurrentLineContent(t, `do{`) f.GoToMarker(t, "3") - f.VerifyCurrentLineContentIs(t, " do") + f.VerifyCurrentLineContent(t, ` do`) f.GoToMarker(t, "4") - f.VerifyCurrentLineContentIs(t, "do{") + f.VerifyCurrentLineContent(t, `do{`) f.GoToMarker(t, "5") - f.VerifyCurrentLineContentIs(t, "}while(a!==b)") + f.VerifyCurrentLineContent(t, `}while(a!==b)`) f.GoToMarker(t, "6") - f.VerifyCurrentLineContentIs(t, "}while(a!==b)") + f.VerifyCurrentLineContent(t, `}while(a!==b)`) f.GoToMarker(t, "7") - f.VerifyCurrentLineContentIs(t, "}while(a!==b)") + 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..d47530ec70 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..c099a5e9d2 --- /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) { + fourslash.SkipIfFailing(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 index cd3ff749a4..9828e3570c 100644 --- a/internal/fourslash/tests/gen/formattingOnSemiColon_test.go +++ b/internal/fourslash/tests/gen/formattingOnSemiColon_test.go @@ -16,5 +16,5 @@ func TestFormattingOnSemiColon(t *testing.T) { defer done() f.GoToEOF(t) f.Insert(t, ";") - f.VerifyCurrentFileContentIs(t, "var a = b + c ^ d - e * ++f;") + 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..1d6b1801bd --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..1f4bf7974b --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..d4bcf334b4 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..21a144ceee --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..4316637542 --- /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) { + fourslash.SkipIfFailing(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..21dec178f6 --- /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) { + fourslash.SkipIfFailing(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 index 30ffaffff3..247b9c7297 100644 --- a/internal/fourslash/tests/gen/formattingRegexes_test.go +++ b/internal/fourslash/tests/gen/formattingRegexes_test.go @@ -16,5 +16,5 @@ func TestFormattingRegexes(t *testing.T) { defer done() f.GoToMarker(t, "1") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "removeAllButLast(sortedTypes, undefinedType, /keepNullableType**/ true);") + 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..c8f2f84afa --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..505d667af5 --- /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) { + fourslash.SkipIfFailing(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..51bc6a4abe --- /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) { + fourslash.SkipIfFailing(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 index e6759eff6f..9ade18b660 100644 --- a/internal/fourslash/tests/gen/formattingSpaceAfterCommaBeforeOpenParen_test.go +++ b/internal/fourslash/tests/gen/formattingSpaceAfterCommaBeforeOpenParen_test.go @@ -17,8 +17,8 @@ foo(a,(c).d)/*2*/` defer done() f.GoToMarker(t, "1") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "foo(a, (b));") + f.VerifyCurrentLineContent(t, `foo(a, (b));`) f.GoToMarker(t, "2") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "foo(a, (c).d);") + 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..81aba10be3 --- /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) { + fourslash.SkipIfFailing(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..5b8e70d8dd --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..b352dcf4fa --- /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) { + fourslash.SkipIfFailing(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..ccf41bf0e7 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..e1e7132ba7 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index 1855e066d1..e06a58bd16 100644 --- a/internal/fourslash/tests/gen/formattingTemplatesWithNewline_test.go +++ b/internal/fourslash/tests/gen/formattingTemplatesWithNewline_test.go @@ -18,5 +18,5 @@ func TestFormattingTemplatesWithNewline(t *testing.T) { defer done() f.GoToMarker(t, "") f.Insert(t, "\n") - f.VerifyCurrentLineContentIs(t, "1") + f.VerifyCurrentLineContent(t, `1`) } diff --git a/internal/fourslash/tests/gen/formattingTemplates_test.go b/internal/fourslash/tests/gen/formattingTemplates_test.go index ae4f03e5af..25632eae3e 100644 --- a/internal/fourslash/tests/gen/formattingTemplates_test.go +++ b/internal/fourslash/tests/gen/formattingTemplates_test.go @@ -17,8 +17,8 @@ String.call ` + "`" + `${123} ${456}` + "`" + `/*2*/` defer done() f.GoToMarker(t, "1") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "String.call`${123}`;") + f.VerifyCurrentLineContent(t, "String.call`${123}`;") f.GoToMarker(t, "2") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "String.call`${123} ${456}`;") + 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..2819416501 --- /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) { + fourslash.SkipIfFailing(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..f86886f944 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index 3eb4204688..26ce255a9d 100644 --- a/internal/fourslash/tests/gen/formattingWithMultilineComments_test.go +++ b/internal/fourslash/tests/gen/formattingWithMultilineComments_test.go @@ -18,5 +18,5 @@ func TestFormattingWithMultilineComments(t *testing.T) { f.GoToMarker(t, "1") f.InsertLine(t, "") f.GoToMarker(t, "2") - f.VerifyCurrentLineContentIs(t, " */() => {") + 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..004eb3ca9e --- /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) { + fourslash.SkipIfFailing(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..14c5d4ec2d --- /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) { + fourslash.SkipIfFailing(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..4d7278950c --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index cf7dd505f6..111ca31244 100644 --- a/internal/fourslash/tests/gen/functionTypeFormatting_test.go +++ b/internal/fourslash/tests/gen/functionTypeFormatting_test.go @@ -16,5 +16,5 @@ func TestFunctionTypeFormatting(t *testing.T) { defer done() f.GoToMarker(t, "") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "var x: () => string;") + 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..b53eecee47 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..d56b790407 --- /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) { + fourslash.SkipIfFailing(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..ff4f937877 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..d101fba626 --- /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) { + fourslash.SkipIfFailing(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..5f1e4c9504 --- /dev/null +++ b/internal/fourslash/tests/gen/importNameCodeFix_externalNonRelateive2_test.go @@ -0,0 +1,57 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls/lsutil" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestImportNameCodeFix_externalNonRelateive2(t *testing.T) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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`, + }, &lsutil.UserPreferences{ImportModuleSpecifierPreference: "project-relative"}) + f.GoToMarker(t, "internal2internal") + f.VerifyImportFixAtPosition(t, []string{ + `import { utils } from "./utils"; + +utils`, + }, &lsutil.UserPreferences{ImportModuleSpecifierPreference: "project-relative"}) + f.GoToMarker(t, "external2external") + f.VerifyImportFixAtPosition(t, []string{ + `import { shared } from "./constants"; + +shared`, + }, &lsutil.UserPreferences{ImportModuleSpecifierPreference: "project-relative"}) +} 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..2422afc024 --- /dev/null +++ b/internal/fourslash/tests/gen/importNameCodeFix_externalNonRelative1_test.go @@ -0,0 +1,66 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls/lsutil" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestImportNameCodeFix_externalNonRelative1(t *testing.T) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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`, + }, &lsutil.UserPreferences{ImportModuleSpecifierPreference: "project-relative"}) + f.GoToMarker(t, "internal") + f.VerifyImportFixAtPosition(t, []string{ + `import { Pkg2 } from "../../utils"; + +Pkg2`, + }, &lsutil.UserPreferences{ImportModuleSpecifierPreference: "project-relative"}) +} diff --git a/internal/fourslash/tests/gen/importTypeFormatting_test.go b/internal/fourslash/tests/gen/importTypeFormatting_test.go new file mode 100644 index 0000000000..8434c29db4 --- /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) { + fourslash.SkipIfFailing(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 index e2321fb0e0..a35ed32c7a 100644 --- a/internal/fourslash/tests/gen/indentAfterFunctionClosingBraces_test.go +++ b/internal/fourslash/tests/gen/indentAfterFunctionClosingBraces_test.go @@ -21,5 +21,5 @@ func TestIndentAfterFunctionClosingBraces(t *testing.T) { f.GoToMarker(t, "2") f.InsertLine(t, "") f.GoToMarker(t, "1") - f.VerifyCurrentLineContentIs(t, " }") + 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..2b772bd6c1 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..88e6cdc514 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..88612fff2c --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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 index 906f01e0ca..b248129fc8 100644 --- a/internal/fourslash/tests/gen/paste_test.go +++ b/internal/fourslash/tests/gen/paste_test.go @@ -16,5 +16,5 @@ func TestPaste(t *testing.T) { defer done() f.GoToMarker(t, "") f.Paste(t, "x,y,z") - f.VerifyCurrentLineContentIs(t, "fn(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 index c0b7292c8c..e683b85ecc 100644 --- a/internal/fourslash/tests/gen/semicolonFormattingAfterArrayLiteral_test.go +++ b/internal/fourslash/tests/gen/semicolonFormattingAfterArrayLiteral_test.go @@ -16,5 +16,5 @@ func TestSemicolonFormattingAfterArrayLiteral(t *testing.T) { defer done() f.GoToMarker(t, "") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "[1, 2];") + f.VerifyCurrentLineContent(t, `[1, 2];`) } diff --git a/internal/fourslash/tests/gen/semicolonFormattingInsideAComment_test.go b/internal/fourslash/tests/gen/semicolonFormattingInsideAComment_test.go index 9731a43eea..8ecf5b601d 100644 --- a/internal/fourslash/tests/gen/semicolonFormattingInsideAComment_test.go +++ b/internal/fourslash/tests/gen/semicolonFormattingInsideAComment_test.go @@ -16,5 +16,5 @@ func TestSemicolonFormattingInsideAComment(t *testing.T) { defer done() f.GoToMarker(t, "") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, " //;") + f.VerifyCurrentLineContent(t, ` //;`) } diff --git a/internal/fourslash/tests/gen/semicolonFormattingInsideAStringLiteral_test.go b/internal/fourslash/tests/gen/semicolonFormattingInsideAStringLiteral_test.go index e8e854b85e..599cc2d66c 100644 --- a/internal/fourslash/tests/gen/semicolonFormattingInsideAStringLiteral_test.go +++ b/internal/fourslash/tests/gen/semicolonFormattingInsideAStringLiteral_test.go @@ -16,5 +16,5 @@ func TestSemicolonFormattingInsideAStringLiteral(t *testing.T) { defer done() f.GoToMarker(t, "") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, " var x = \"string;") + f.VerifyCurrentLineContent(t, ` var x = "string;`) } diff --git a/internal/fourslash/tests/gen/semicolonFormattingNestedStatements_test.go b/internal/fourslash/tests/gen/semicolonFormattingNestedStatements_test.go index e9ac2d6826..b746ec3448 100644 --- a/internal/fourslash/tests/gen/semicolonFormattingNestedStatements_test.go +++ b/internal/fourslash/tests/gen/semicolonFormattingNestedStatements_test.go @@ -21,9 +21,9 @@ var x = 0/*innermost*/ defer done() f.GoToMarker(t, "innermost") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, " var x = 0;") + f.VerifyCurrentLineContent(t, ` var x = 0;`) f.GoToMarker(t, "directParent") - f.VerifyCurrentLineContentIs(t, " if (true)") + f.VerifyCurrentLineContent(t, ` if (true)`) f.GoToMarker(t, "parentOutsideBlock") - f.VerifyCurrentLineContentIs(t, "if (true)") + f.VerifyCurrentLineContent(t, `if (true)`) } diff --git a/internal/fourslash/tests/gen/semicolonFormatting_test.go b/internal/fourslash/tests/gen/semicolonFormatting_test.go index 656752ec24..f807e17d07 100644 --- a/internal/fourslash/tests/gen/semicolonFormatting_test.go +++ b/internal/fourslash/tests/gen/semicolonFormatting_test.go @@ -16,5 +16,5 @@ func TestSemicolonFormatting(t *testing.T) { defer done() f.GoToEOF(t) f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "function of1(b: { r: { c: number;") + 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 index cd8846c5c4..9ac5badfaf 100644 --- a/internal/fourslash/tests/gen/singleLineTypeLiteralFormatting_test.go +++ b/internal/fourslash/tests/gen/singleLineTypeLiteralFormatting_test.go @@ -16,5 +16,5 @@ func TestSingleLineTypeLiteralFormatting(t *testing.T) { defer done() f.GoToMarker(t, "") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "function of1(b: { r: { c: number;") + 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..15bb8391f0 --- /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) { + fourslash.SkipIfFailing(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 index ae954e3766..077e3a038a 100644 --- a/internal/fourslash/tests/gen/spaceAfterConstructor_test.go +++ b/internal/fourslash/tests/gen/spaceAfterConstructor_test.go @@ -21,5 +21,5 @@ func TestSpaceAfterConstructor(t *testing.T) { f.GoToMarker(t, "2") f.Insert(t, "}") f.GoToMarker(t, "1") - f.VerifyCurrentLineContentIs(t, " constructor(processId: number) {") + 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..37359e8601 --- /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) { + fourslash.SkipIfFailing(t) + t.Parallel() + 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..1f3cf8f289 --- /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) { + fourslash.SkipIfFailing(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..2098809ec4 --- /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) { + fourslash.SkipIfFailing(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 index 5c87ed2c14..b616ada844 100644 --- a/internal/fourslash/tests/gen/tabbingAfterNewlineInsertedBeforeWhile_test.go +++ b/internal/fourslash/tests/gen/tabbingAfterNewlineInsertedBeforeWhile_test.go @@ -18,5 +18,5 @@ func TestTabbingAfterNewlineInsertedBeforeWhile(t *testing.T) { defer done() f.GoToMarker(t, "") f.InsertLine(t, "") - f.VerifyCurrentLineContentIs(t, " while (true) { }") + 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..e24290c054 --- /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) { + fourslash.SkipIfFailing(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 index e521d4f9f5..3c9c2cdc2a 100644 --- a/internal/fourslash/tests/gen/unclosedStringLiteralAutoformating_test.go +++ b/internal/fourslash/tests/gen/unclosedStringLiteralAutoformating_test.go @@ -18,5 +18,5 @@ class Foo { defer done() f.GoToMarker(t, "") f.Insert(t, "}") - f.VerifyCurrentLineContentIs(t, "}") + f.VerifyCurrentLineContent(t, `}`) } diff --git a/internal/fourslash/tests/gen/whiteSpaceBeforeReturnTypeFormatting_test.go b/internal/fourslash/tests/gen/whiteSpaceBeforeReturnTypeFormatting_test.go index f26c3e3040..e1318b4b91 100644 --- a/internal/fourslash/tests/gen/whiteSpaceBeforeReturnTypeFormatting_test.go +++ b/internal/fourslash/tests/gen/whiteSpaceBeforeReturnTypeFormatting_test.go @@ -16,5 +16,5 @@ func TestWhiteSpaceBeforeReturnTypeFormatting(t *testing.T) { defer done() f.GoToMarker(t, "") f.Insert(t, ";") - f.VerifyCurrentLineContentIs(t, "var x: () => string;") + f.VerifyCurrentLineContent(t, `var x: () => string;`) } diff --git a/internal/fourslash/tests/gen/whiteSpaceTrimming2_test.go b/internal/fourslash/tests/gen/whiteSpaceTrimming2_test.go index f7ce9baffc..b43dc422e4 100644 --- a/internal/fourslash/tests/gen/whiteSpaceTrimming2_test.go +++ b/internal/fourslash/tests/gen/whiteSpaceTrimming2_test.go @@ -25,5 +25,5 @@ let templateTail = ` + "`" + `/* ${1 + 2} /*4*/` + "`" + `;` f.Insert(t, "\n") f.GoToMarker(t, "4") f.Insert(t, "\n") - f.VerifyCurrentFileContentIs(t, "let noSubTemplate = `/* \n`;\nlet templateHead = `/* \n${1 + 2}`;\nlet templateMiddle = `/* ${1 + 2\n }`;\nlet templateTail = `/* ${1 + 2} \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 index b41f0f25b0..695be4b9cc 100644 --- a/internal/fourslash/tests/gen/whiteSpaceTrimming3_test.go +++ b/internal/fourslash/tests/gen/whiteSpaceTrimming3_test.go @@ -18,5 +18,5 @@ bar \ defer done() f.GoToMarker(t, "1") f.Insert(t, ";") - f.VerifyCurrentFileContentIs(t, "let t = \"foo \\\nbar \\ \n\";") + 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 index 469b30f611..3759933177 100644 --- a/internal/fourslash/tests/gen/whiteSpaceTrimming4_test.go +++ b/internal/fourslash/tests/gen/whiteSpaceTrimming4_test.go @@ -16,5 +16,5 @@ func TestWhiteSpaceTrimming4(t *testing.T) { defer done() f.GoToMarker(t, "1") f.Insert(t, "\n") - f.VerifyCurrentFileContentIs(t, "var re = /\\w+\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 index c12e938e09..d24e4ea69b 100644 --- a/internal/fourslash/tests/gen/whiteSpaceTrimming_test.go +++ b/internal/fourslash/tests/gen/whiteSpaceTrimming_test.go @@ -18,5 +18,8 @@ func TestWhiteSpaceTrimming(t *testing.T) { defer done() f.GoToMarker(t, "err") f.Insert(t, "\n") - f.VerifyCurrentFileContentIs(t, "if (true) { \n // \n\n}") + f.VerifyCurrentFileContent(t, `if (true) { + // + +}`) } diff --git a/internal/ls/change/tracker.go b/internal/ls/change/tracker.go index e9de6aec88..b55afc2aa4 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 a911fe902e..3bdd7a2d0e 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..355a44ac68 100644 --- a/internal/ls/format.go +++ b/internal/ls/format.go @@ -8,24 +8,11 @@ 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) - 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 { @@ -46,7 +33,7 @@ func (l *LanguageService) ProvideFormatDocument( edits := l.toLSProtoTextEdits(file, l.getFormattingEditsForDocument( ctx, file, - toFormatCodeSettings(options, l.GetProgram().Options().NewLine.GetNewLineCharacter()), + lsutil.FromLSFormatOptions(l.UserPreferences().FormatCodeSettings, options), )) return lsproto.TextEditsOrNull{TextEdits: &edits}, nil } @@ -61,7 +48,7 @@ func (l *LanguageService) ProvideFormatDocumentRange( edits := l.toLSProtoTextEdits(file, l.getFormattingEditsForRange( ctx, file, - toFormatCodeSettings(options, l.GetProgram().Options().NewLine.GetNewLineCharacter()), + lsutil.FromLSFormatOptions(l.UserPreferences().FormatCodeSettings, options), l.converters.FromLSPRange(file, r), )) return lsproto.TextEditsOrNull{TextEdits: &edits}, nil @@ -78,7 +65,7 @@ func (l *LanguageService) ProvideFormatDocumentOnType( edits := l.toLSProtoTextEdits(file, l.getFormattingEditsAfterKeystroke( ctx, file, - toFormatCodeSettings(options, l.GetProgram().Options().NewLine.GetNewLineCharacter()), + lsutil.FromLSFormatOptions(l.UserPreferences().FormatCodeSettings, options), int(l.converters.LineAndCharacterToPosition(file, position)), character, )) @@ -88,7 +75,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 +85,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 +94,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 2cfe172468..f215634994 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" @@ -42,11 +41,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..a62c6c27d6 --- /dev/null +++ b/internal/ls/lsutil/formatcodeoptions.go @@ -0,0 +1,218 @@ +package lsutil + +import ( + "strings" + + "github.com/microsoft/typescript-go/internal/core" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "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 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 + 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 d57197a027..766d3788b5 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, @@ -26,6 +28,8 @@ func NewDefaultUserPreferences() *UserPreferences { } type UserPreferences struct { + FormatCodeSettings *FormatCodeSettings + QuotePreference QuotePreference LazyConfiguredProjectsFromExternalProject bool // !!! @@ -372,20 +376,7 @@ 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 @@ -408,7 +399,7 @@ func (p *UserPreferences) parseWorker(config map[string]any) { case "workspaceSymbols": p.parseWorkspaceSymbols(values) case "format": - // !!! + p.FormatCodeSettings.Parse(values) case "tsserver": // !!! case "tsc": @@ -416,9 +407,11 @@ func (p *UserPreferences) parseWorker(config map[string]any) { case "experimental": // !!! default: - p.set(name, values) + p.Set(name, values) + p.FormatCodeSettings.Set(name, values) } } + return p } func (p *UserPreferences) parseAll(prefs any) { @@ -427,7 +420,7 @@ func (p *UserPreferences) parseAll(prefs any) { return } for name, value := range prefsMap { - p.set(name, value) + p.Set(name, value) } } @@ -442,7 +435,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": @@ -459,7 +452,7 @@ func (p *UserPreferences) parseInlayHints(prefs any) { } } else { // non-vscode case - p.set(name, v) + p.Set(name, v) } } } @@ -472,9 +465,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) } } } @@ -487,11 +480,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) } } } @@ -504,19 +497,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) } } } @@ -530,7 +523,7 @@ func (p *UserPreferences) parsePreferences(prefs any) { if name == "organizeImports" { p.parseOrganizeImportsPreferences(value) } else { - p.set(name, value) + p.Set(name, value) } } } @@ -542,7 +535,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 { @@ -558,18 +551,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) } } } @@ -586,7 +579,7 @@ func (p *UserPreferences) parseWorkspaceSymbols(prefs any) { case "excludeLibrarySymbols": p.ExcludeLibrarySymbolsInNavTo = parseBoolWithDefault(value, true) default: - p.set(name, value) + p.Set(name, value) } } } @@ -625,7 +618,7 @@ func parseIntWithDefault(val any, defaultV int) int { return defaultV } -func (p *UserPreferences) set(name string, value any) { +func (p *UserPreferences) Set(name string, value any) bool { switch strings.ToLower(name) { case "quotePreference": p.QuotePreference = parseQuotePreference(value) @@ -698,7 +691,7 @@ func (p *UserPreferences) set(name string, value any) { case "includeinlayenummembervaluehints": p.InlayHints.IncludeInlayEnumMemberValueHints = parseBoolWithDefault(value, false) case "excludelibrarysymbolsinnavto": - p.ExcludeLibrarySymbolsInNavTo = parseBoolWithDefault(value, true) + p.ExcludeLibrarySymbolsInNavTo = parseBoolWithDefault(value, false) case "disablesuggestions": p.DisableSuggestions = parseBoolWithDefault(value, false) case "disablelinetextinreferences": @@ -717,5 +710,11 @@ func (p *UserPreferences) set(name string, value any) { p.CodeLens.ImplementationsCodeLensShowOnInterfaceMethods = parseBoolWithDefault(value, false) case "implementationscodelensshowonallclassmethods": p.CodeLens.ImplementationsCodeLensShowOnAllClassMethods = parseBoolWithDefault(value, false) + default: + if p.FormatCodeSettings == nil { + p.FormatCodeSettings = GetDefaultFormatCodeSettings() + } + return p.FormatCodeSettings.Set(name, value) } + return true } diff --git a/internal/lsp/server.go b/internal/lsp/server.go index ad30b34eae..b3f57cee58 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -19,7 +19,6 @@ import ( "github.com/microsoft/typescript-go/internal/locale" "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" @@ -269,30 +268,32 @@ func (s *Server) RefreshCodeLens(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) { caps := lsproto.GetClientCapabilities(ctx) if !caps.Workspace.Configuration { // if no configuration request capapbility, return default preferences - return s.session.NewUserPreferences(), nil + return project.NewConfig(s.session.NewUserPreferences()), nil } configs, err := sendClientRequest(ctx, s, lsproto.WorkspaceConfigurationInfo, &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) - } - s.logger.Infof("configuration: %+v, %T", configs, configs) - userPreferences := s.session.NewUserPreferences() - for _, item := range configs { - if parsed := userPreferences.Parse(item); parsed != nil { - return parsed, nil - } + return &project.Config{}, fmt.Errorf("configure request failed: %w", err) } - return userPreferences, nil + return project.ParseConfiguration(configs), nil } func (s *Server) Run(ctx context.Context) error { @@ -924,17 +925,14 @@ func (s *Server) handleExit(ctx context.Context, params any) error { } func (s *Server) handleDidChangeWorkspaceConfiguration(ctx context.Context, params *lsproto.DidChangeConfigurationParams) error { - settings, ok := params.Settings.(map[string]any) - if !ok { + // !!! only implemented because needed for fourslash + if params.Settings == nil { return nil + } 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"], settings["ts"], settings["javascript"], settings["js"]})) } - // !!! Both the 'javascript' and 'js/ts' scopes need to be checked for settings as well. - tsSettings := settings["typescript"] - userPreferences := s.session.UserPreferences() - if parsed := userPreferences.Parse(tsSettings); parsed != nil { - userPreferences = parsed - } - s.session.Configure(userPreferences) return nil } diff --git a/internal/project/configuration.go b/internal/project/configuration.go new file mode 100644 index 0000000000..797fde9512 --- /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 0ef5d204b9..da3391f4d6 100644 --- a/internal/project/session.go +++ b/internal/project/session.go @@ -87,8 +87,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 @@ -163,9 +164,11 @@ func NewSession(init *SessionInit) *Session { extendedConfigCache, &ConfigFileRegistry{}, nil, - Config{}, + nil, toPath, ), + 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), } @@ -190,16 +193,25 @@ func (s *Session) GetCurrentDirectory() string { return s.options.CurrentDirectory } -// Gets current UserPreferences, always a copy +// Gets copy of current configuration +func (s *Session) Config() *Config { + s.configRWMu.Lock() + defer s.configRWMu.Unlock() + return s.workspaceConfig.Copy() +} + +// !!! ts/js preferences +// Gets copy of current UserPreferences 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 @@ -207,23 +219,26 @@ 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) { + // `config` should never be nil s.configRWMu.Lock() defer s.configRWMu.Unlock() s.pendingConfigChanges = true + oldConfig := s.workspaceConfig.Copy() + s.workspaceConfig = s.workspaceConfig.CopyInto(config) // Tell the client to re-request certain commands depending on user preference changes. - oldUserPreferences := s.userPreferences - s.userPreferences = userPreferences - if oldUserPreferences != userPreferences && oldUserPreferences != nil && userPreferences != nil { - s.refreshInlayHintsIfNeeded(oldUserPreferences, userPreferences) - s.refreshCodeLensIfNeeded(oldUserPreferences, userPreferences) + if oldConfig != config { + + s.refreshInlayHintsIfNeeded(oldConfig, config) + s.refreshCodeLensIfNeeded(oldConfig, 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) { @@ -705,9 +720,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 @@ -795,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 50889c7cbd..0f0f1e6119 100644 --- a/internal/project/snapshot.go +++ b/internal/project/snapshot.go @@ -10,7 +10,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" "github.com/microsoft/typescript-go/internal/ls/lsconv" "github.com/microsoft/typescript-go/internal/ls/lsutil" @@ -38,7 +37,7 @@ type Snapshot struct { ProjectCollection *ProjectCollection ConfigFileRegistry *ConfigFileRegistry compilerOptionsForInferredProjects *core.CompilerOptions - config Config + config *Config builderLogs *logging.LogTree apiError error @@ -53,9 +52,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, @@ -105,11 +107,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 { @@ -187,13 +189,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 @@ -349,12 +344,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() diff --git a/internal/scanner/scanner.go b/internal/scanner/scanner.go index a8d4718ec2..2b335e48f0 100644 --- a/internal/scanner/scanner.go +++ b/internal/scanner/scanner.go @@ -2346,9 +2346,8 @@ func getErrorRangeForArrowFunction(sourceFile *ast.SourceFile, node *ast.Node) c startLine := GetECMALineOfPosition(sourceFile, body.Pos()) endLine := GetECMALineOfPosition(sourceFile, body.End()) if startLine < endLine { - // The arrow function spans multiple lines, - // make the error span be the first line, inclusive. - return core.NewTextRange(pos, GetECMAEndLinePosition(sourceFile, startLine)) + // The arrow function spans multiple lines, make the error span be the first line, inclusive. + return core.NewTextRange(pos, GetECMAEndLinePosition(sourceFile, startLine)+1) } } return core.NewTextRange(pos, node.End()) @@ -2458,7 +2457,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/documentHighlights/getOccurrencesIfElseBroken.baseline.jsonc b/testdata/baselines/reference/fourslash/documentHighlights/getOccurrencesIfElseBroken.baseline.jsonc new file mode 100644 index 0000000000..c1c381e16a --- /dev/null +++ b/testdata/baselines/reference/fourslash/documentHighlights/getOccurrencesIfElseBroken.baseline.jsonc @@ -0,0 +1,57 @@ +// === documentHighlights === +// === /getOccurrencesIfElseBroken.ts === +// /*HIGHLIGHTS*/[|if|] (true) { +// var x = 1; +// } +// [|else if|] () +// [|else if|] +// [|else|] /* whar garbl */ [|if|] (if (true) { } else { }) +// else + + + +// === documentHighlights === +// === /getOccurrencesIfElseBroken.ts === +// [|if|] (true) { +// var x = 1; +// } +// /*HIGHLIGHTS*/[|else if|] () +// [|else if|] +// [|else|] /* whar garbl */ [|if|] (if (true) { } else { }) +// else + + + +// === documentHighlights === +// === /getOccurrencesIfElseBroken.ts === +// [|if|] (true) { +// var x = 1; +// } +// [|else if|] () +// /*HIGHLIGHTS*/[|else if|] +// [|else|] /* whar garbl */ [|if|] (if (true) { } else { }) +// else + + + +// === documentHighlights === +// === /getOccurrencesIfElseBroken.ts === +// [|if|] (true) { +// var x = 1; +// } +// [|else if|] () +// [|else if|] +// /*HIGHLIGHTS*/[|else|] /* whar garbl */ [|if|] (if (true) { } else { }) +// else + + + +// === documentHighlights === +// === /getOccurrencesIfElseBroken.ts === +// [|if|] (true) { +// var x = 1; +// } +// [|else if|] () +// [|else if|] +// [|else|] /* whar garbl */ /*HIGHLIGHTS*/[|if|] (if (true) { } else { }) +// else \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/state/codeLensAcrossProjects.baseline b/testdata/baselines/reference/fourslash/state/codeLensAcrossProjects.baseline index 6425dbacf4..a2463cbaeb 100644 --- a/testdata/baselines/reference/fourslash/state/codeLensAcrossProjects.baseline +++ b/testdata/baselines/reference/fourslash/state/codeLensAcrossProjects.baseline @@ -162,6 +162,7 @@ Config File Names:: "params": { "settings": { "typescript": { + "FormatCodeSettings": null, "QuotePreference": "", "LazyConfiguredProjectsFromExternalProject": false, "MaximumHoverLength": 0, @@ -610,6 +611,35 @@ Config:: "params": { "settings": { "typescript": { + "FormatCodeSettings": { + "BaseIndentSize": 0, + "IndentSize": 4, + "TabSize": 4, + "NewLineCharacter": "\n", + "ConvertTabsToSpaces": true, + "IndentStyle": 2, + "TrimTrailingWhitespace": true, + "InsertSpaceAfterCommaDelimiter": true, + "InsertSpaceAfterSemicolonInForStatements": true, + "InsertSpaceBeforeAndAfterBinaryOperators": true, + "InsertSpaceAfterConstructor": false, + "InsertSpaceAfterKeywordsInControlFlowStatements": true, + "InsertSpaceAfterFunctionKeywordForAnonymousFunctions": false, + "InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, + "InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, + "InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, + "InsertSpaceAfterOpeningAndBeforeClosingEmptyBraces": null, + "InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false, + "InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false, + "InsertSpaceAfterTypeAssertion": null, + "InsertSpaceBeforeFunctionParenthesis": false, + "PlaceOpenBraceOnNewLineForFunctions": false, + "PlaceOpenBraceOnNewLineForControlBlocks": false, + "InsertSpaceBeforeTypeAnnotation": null, + "IndentMultiLineObjectLiteralBeginningOnBlankLine": null, + "Semicolons": "ignore", + "IndentSwitchCase": true + }, "QuotePreference": "", "LazyConfiguredProjectsFromExternalProject": false, "MaximumHoverLength": 0, 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 + } + } +}