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
96 changes: 96 additions & 0 deletions internal/fourslash/tests/importModuleSpecifierEnding_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/fourslash"
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
"github.com/microsoft/typescript-go/internal/ls/lsutil"
"github.com/microsoft/typescript-go/internal/modulespecifiers"
"github.com/microsoft/typescript-go/internal/testutil"
)

func TestImportModuleSpecifierEndingMinimal(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /project/helper.ts
export const helperFunc = () => {};

// @Filename: /project/index.ts
helper/**/`

f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
UserPreferences: &lsutil.UserPreferences{
IncludeCompletionsForModuleExports: core.TSTrue,
IncludeCompletionsForImportStatements: core.TSTrue,
ImportModuleSpecifierEnding: modulespecifiers.ImportModuleSpecifierEndingPreferenceMinimal,
},
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{"helperFunc"},
},
})
// Verify using baseline to capture the actual source
f.BaselineAutoImportsCompletions(t, []string{""})
}

func TestImportModuleSpecifierEndingJs(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /project/helper.ts
export const helperFunc = () => {};

// @Filename: /project/index.ts
helper/**/`

f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
UserPreferences: &lsutil.UserPreferences{
IncludeCompletionsForModuleExports: core.TSTrue,
IncludeCompletionsForImportStatements: core.TSTrue,
ImportModuleSpecifierEnding: modulespecifiers.ImportModuleSpecifierEndingPreferenceJs,
},
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{"helperFunc"},
},
})
// Verify using baseline to capture the actual source
f.BaselineAutoImportsCompletions(t, []string{""})
}

func TestImportModuleSpecifierEndingIndex(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /project/utils/index.ts
export const helperFunc = () => {};

// @Filename: /project/index.ts
helper/**/`

f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
UserPreferences: &lsutil.UserPreferences{
IncludeCompletionsForModuleExports: core.TSTrue,
IncludeCompletionsForImportStatements: core.TSTrue,
ImportModuleSpecifierEnding: modulespecifiers.ImportModuleSpecifierEndingPreferenceIndex,
},
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{"helperFunc"},
},
})
// Verify using baseline to capture the actual source
f.BaselineAutoImportsCompletions(t, []string{""})
}
130 changes: 130 additions & 0 deletions internal/fourslash/tests/importModuleSpecifierPreference_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/fourslash"
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
"github.com/microsoft/typescript-go/internal/ls/lsutil"
"github.com/microsoft/typescript-go/internal/modulespecifiers"
"github.com/microsoft/typescript-go/internal/testutil"
)

func TestImportModuleSpecifierPreferenceShortest(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /project/src/utils/helper.ts
export const helperFunc = () => {};

// @Filename: /project/src/index.ts
helper/**/`

f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
UserPreferences: &lsutil.UserPreferences{
IncludeCompletionsForModuleExports: core.TSTrue,
IncludeCompletionsForImportStatements: core.TSTrue,
ImportModuleSpecifierPreference: modulespecifiers.ImportModuleSpecifierPreferenceShortest,
},
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{"helperFunc"},
},
})
// Verify using baseline to capture the actual source
f.BaselineAutoImportsCompletions(t, []string{""})
}

func TestImportModuleSpecifierPreferenceRelative(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /project/src/utils/helper.ts
export const helperFunc = () => {};

// @Filename: /project/src/index.ts
helper/**/`

f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
UserPreferences: &lsutil.UserPreferences{
IncludeCompletionsForModuleExports: core.TSTrue,
IncludeCompletionsForImportStatements: core.TSTrue,
ImportModuleSpecifierPreference: modulespecifiers.ImportModuleSpecifierPreferenceRelative,
},
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{"helperFunc"},
},
})
// Verify using baseline to capture the actual source
f.BaselineAutoImportsCompletions(t, []string{""})
}

func TestImportModuleSpecifierPreferenceNonRelative(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /project/tsconfig.json
{ "compilerOptions": { "baseUrl": "." } }

// @Filename: /project/src/utils/helper.ts
export const helperFunc = () => {};

// @Filename: /project/src/index.ts
helper/**/`

f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
UserPreferences: &lsutil.UserPreferences{
IncludeCompletionsForModuleExports: core.TSTrue,
IncludeCompletionsForImportStatements: core.TSTrue,
ImportModuleSpecifierPreference: modulespecifiers.ImportModuleSpecifierPreferenceNonRelative,
},
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{"helperFunc"},
},
})
// Verify using baseline to capture the actual source
f.BaselineAutoImportsCompletions(t, []string{""})
}

func TestImportModuleSpecifierPreferenceProjectRelative(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /project/tsconfig.json
{ "compilerOptions": { "baseUrl": ".", "paths": { "~/utils/*": ["./src/utils/*"] } } }

// @Filename: /project/src/utils/helper.ts
export const helperFunc = () => {};

// @Filename: /project/src/index.ts
helper/**/`

f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
UserPreferences: &lsutil.UserPreferences{
IncludeCompletionsForModuleExports: core.TSTrue,
IncludeCompletionsForImportStatements: core.TSTrue,
ImportModuleSpecifierPreference: modulespecifiers.ImportModuleSpecifierPreferenceProjectRelative,
},
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{"helperFunc"},
},
})
// Verify using baseline to capture the actual source
f.BaselineAutoImportsCompletions(t, []string{""})
}
4 changes: 2 additions & 2 deletions internal/ls/findallreferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/microsoft/typescript-go/internal/compiler"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/debug"
"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/scanner"
"github.com/microsoft/typescript-go/internal/stringutil"
Expand Down Expand Up @@ -454,7 +454,7 @@ func (l *LanguageService) getImplementationReferenceEntries(ctx context.Context,
return core.FlatMap(symbolsAndEntries, func(s *SymbolAndEntries) []*ReferenceEntry { return s.references })
}

func (l *LanguageService) ProvideRename(ctx context.Context, params *lsproto.RenameParams, prefs *ls.UserPreferences) (lsproto.WorkspaceEditOrNull, error) {
func (l *LanguageService) ProvideRename(ctx context.Context, params *lsproto.RenameParams, prefs *lsutil.UserPreferences) (lsproto.WorkspaceEditOrNull, error) {
program, sourceFile := l.getProgramAndFile(params.TextDocument.Uri)
position := int(l.converters.LineAndCharacterToPosition(sourceFile, params.Position))
node := astnav.GetTouchingPropertyName(sourceFile, position)
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ func (s *Server) handleDocumentSymbol(ctx context.Context, ls *ls.LanguageServic
}

func (s *Server) handleRename(ctx context.Context, languageServer *ls.LanguageService, params *lsproto.RenameParams) (lsproto.RenameResponse, error) {
return languageServer.ProvideRename(ctx, params, &ls.UserPreferences{})
return languageServer.ProvideRename(ctx, params, &lsutil.UserPreferences{})
}

func (s *Server) handleDocumentHighlight(ctx context.Context, ls *ls.LanguageService, params *lsproto.DocumentHighlightParams) (lsproto.DocumentHighlightResponse, error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// === Auto Imports ===
```ts
// @FileName: /project/index.ts
helper/**/
``````ts
import { helperFunc } from "./utils";

helper
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// === Auto Imports ===
```ts
// @FileName: /project/index.ts
helper/**/
``````ts
import { helperFunc } from "./helper";

helper
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// === Auto Imports ===
```ts
// @FileName: /project/index.ts
helper/**/
``````ts
import { helperFunc } from "./helper";

helper
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// === Auto Imports ===
```ts
// @FileName: /project/src/index.ts
helper/**/
``````ts
import { helperFunc } from "./utils/helper";

helper
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// === Auto Imports ===
```ts
// @FileName: /project/src/index.ts
helper/**/
``````ts
import { helperFunc } from "~/utils/helper";

helper
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// === Auto Imports ===
```ts
// @FileName: /project/src/index.ts
helper/**/
``````ts
import { helperFunc } from "./utils/helper";

helper
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// === Auto Imports ===
```ts
// @FileName: /project/src/index.ts
helper/**/
``````ts
import { helperFunc } from "./utils/helper";

helper
```