Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/tsgo/lsp.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"flag"
"fmt"
"os"
Expand All @@ -14,7 +15,7 @@ import (
"github.com/microsoft/typescript-go/internal/vfs/osvfs"
)

func runLSP(args []string) int {
func runLSP(ctx context.Context, args []string) int {
flag := flag.NewFlagSet("lsp", flag.ContinueOnError)
stdio := flag.Bool("stdio", false, "use stdio for communication")
pprofDir := flag.String("pprofDir", "", "Generate pprof CPU/memory profiles to the given directory.")
Expand Down Expand Up @@ -51,7 +52,7 @@ func runLSP(args []string) int {
TypingsLocation: typingsLocation,
})

if err := s.Run(); err != nil {
if err := s.Run(ctx); err != nil {
return 1
}
return 0
Expand Down
8 changes: 7 additions & 1 deletion cmd/tsgo/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package main

import (
"context"
"os"
"os/signal"
"syscall"

"github.com/microsoft/typescript-go/internal/execute"
)
Expand All @@ -11,11 +14,14 @@ func main() {
}

func runMain() int {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()

args := os.Args[1:]
if len(args) > 0 {
switch args[0] {
case "--lsp":
return runLSP(args[1:])
return runLSP(ctx, args[1:])
case "--api":
return runAPI(args[1:])
}
Expand Down
20 changes: 14 additions & 6 deletions internal/fourslash/fourslash.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fourslash

import (
"context"
"fmt"
"io"
"maps"
Expand Down Expand Up @@ -128,6 +129,7 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
// Just skip this for now.
t.Skip("bundled files are not embedded")
}

fileName := getBaseFileNameFromTest(t) + tspath.ExtensionTs
testfs := make(map[string]string)
scriptInfos := make(map[string]*scriptInfo)
Expand All @@ -147,11 +149,10 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
outputReader, outputWriter := newLSPPipe()
fs := bundled.WrapFS(vfstest.FromMap(testfs, true /*useCaseSensitiveFileNames*/))

var err strings.Builder
server := lsp.NewServer(&lsp.ServerOptions{
In: inputReader,
Out: outputWriter,
Err: &err,
Err: t.Output(),

Cwd: "/",
FS: fs,
Expand All @@ -160,14 +161,15 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
ParseCache: &parseCache,
})

lspCtx, lspCancel := context.WithCancel(t.Context())
lspErrChan := make(chan error, 1)

go func() {
defer func() {
outputWriter.Close()
}()
err := server.Run()
if err != nil {
t.Error("server error:", err)
}
lspErrChan <- server.Run(lspCtx)
t.Log("LSP server exited")
}()

converters := ls.NewConverters(lsproto.PositionEncodingKindUTF8, func(fileName string) *ls.LSPLineMap {
Expand Down Expand Up @@ -199,7 +201,13 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
f.activeFilename = f.testData.Files[0].fileName

t.Cleanup(func() {
lspCancel()
inputWriter.Close()

t.Log("Waiting for LSP server to exit")
if err := <-lspErrChan; err != nil && lspCtx.Err() == nil {
t.Errorf("LSP server exited with error: %v", err)
}
f.verifyBaselines(t)
})
return f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestAliasMergingWithNamespace(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `namespace bar { }
import bar = bar/**/;`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestAmbientShorthandGotoDefinition(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: declarations.d.ts
declare module /*module*/"jquery"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestArgumentsAreAvailableAfterEditsAtEndOfFunction(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `module Test1 {
class Person {
Expand Down
2 changes: 1 addition & 1 deletion internal/fourslash/tests/gen/augmentedTypesClass1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestAugmentedTypesClass1(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `class c5b { public foo() { } }
module c5b { export var y = 2; } // should be ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestAugmentedTypesClass3Fourslash(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `class c/*1*/5b { public foo() { } }
namespace c/*2*/5b { export var y = 2; } // should be ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestBestCommonTypeObjectLiterals1(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `var a = { name: 'bob', age: 18 };
var b = { name: 'jim', age: 20 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestBestCommonTypeObjectLiterals(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `var a = { name: 'bob', age: 18 };
var b = { name: 'jim', age: 20 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestCodeCompletionEscaping(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: a.js
// @allowJs: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCommentsEnumsFourslash(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `/** Enum of colors*/
enum /*1*/Colors {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestCommentsLinePreservation(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `/** This is firstLine
* This is second Line
Expand Down
2 changes: 1 addition & 1 deletion internal/fourslash/tests/gen/commentsUnion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestCommentsUnion(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `var a: Array<string> | Array<number>;
a./*1*/length`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCompletionAfterQuestionDot(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @strict: true
class User {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCompletionAutoInsertQuestionDot(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @strict: true
interface User {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCompletionCloneQuestionToken(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /file2.ts
type TCallback<T = any> = (options: T) => any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCompletionEntryForArgumentConstrainedToString(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `declare function test<P extends "a" | "b">(p: P): void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCompletionEntryForArrayElementConstrainedToString2(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `declare function test<T extends 'a' | 'b'>(a: { foo: T[] }): void

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCompletionEntryForArrayElementConstrainedToString(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `declare function test<T extends 'a' | 'b'>(a: { foo: T[] }): void

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCompletionEntryForClassMembers_StaticWhenBaseTypeIsNotResolved(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /node_modules/@types/react/index.d.ts
export = React;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCompletionEntryForUnionProperty2(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `interface One {
commonProperty: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCompletionEntryForUnionProperty(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `interface One {
commonProperty: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCompletionForComputedStringProperties(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `const p2 = "p2";
interface A {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCompletionForMetaProperty(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `import./*1*/;
new./*2*/;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCompletionForStringLiteral4(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @allowJs: true
// @Filename: in.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCompletionForStringLiteralExport(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @typeRoots: my_typings
// @Filename: test.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCompletionForStringLiteralImport1(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @typeRoots: my_typings
// @Filename: test.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCompletionForStringLiteralImport2(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @typeRoots: my_typings
// @Filename: test.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCompletionForStringLiteralNonrelativeImport12(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: tests/test0.ts
import * as foo1 from "m/*import_as0*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCompletionForStringLiteralNonrelativeImport14(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: tsconfig.json
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCompletionForStringLiteralNonrelativeImport16(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: tsconfig.json
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCompletionForStringLiteralNonrelativeImport17(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: tsconfig.json
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCompletionForStringLiteralNonrelativeImport18(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: tsconfig.json
{
Expand Down
Loading
Loading