Skip to content
Open
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
26 changes: 26 additions & 0 deletions internal/fourslash/_scripts/convertFourslash.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2695,6 +2695,32 @@ function parseOrganizeImportsArgs(args: readonly ts.Expression[]): [VerifyOrgani
throw new Error(`Unsupported value for organizeImportsIgnoreCase: ${propValue.getText()}`);
}
}
else if (propName === "organizeImportsSort") {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll note that no tests change behavior with this mapping; no manual test changes etc etc. This gives me hope!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, almost, see #4349 (comment)

if (ts.isStringLiteral(propValue)) {
switch (propValue.text) {
case "auto":
prefsFields.push(`${goFieldName}: lsutil.OrganizeImportsSortAuto`);
break;
case "ordinal":
prefsFields.push(`${goFieldName}: lsutil.OrganizeImportsSortOrdinal`);
break;
case "ordinalIgnoreCase":
prefsFields.push(`${goFieldName}: lsutil.OrganizeImportsSortOrdinalIgnoreCase`);
break;
case "natural":
prefsFields.push(`${goFieldName}: lsutil.OrganizeImportsSortNatural`);
break;
case "naturalIgnoreCase":
prefsFields.push(`${goFieldName}: lsutil.OrganizeImportsSortNaturalIgnoreCase`);
break;
default:
throw new Error(`Unsupported value for organizeImportsSort: ${propValue.text}`);
}
}
else {
throw new Error(`Expected string literal for organizeImportsSort, got ${propValue.getText()}`);
}
}
else if (propName === "organizeImportsCollation") {
if (ts.isStringLiteral(propValue)) {
if (propValue.text === "unicode") {
Expand Down
2 changes: 2 additions & 0 deletions internal/fourslash/_scripts/manualTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ navto_excludeLib3
navto_excludeLib4
navto_serverExcludeLib
nodeModulesImportCompletions1
organizeImportsPathsUnicode3
organizeImportsUnicode3
outliningForNonCompleteInterfaceDeclaration
outliningHintSpansForFunction
overloadOnConstCallSignature
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Code generated by convertFourslash; DO NOT EDIT.
// To modify this test, run "npm run makemanual organizeImportsPathsUnicode3"

package fourslash_test

import (
Expand All @@ -14,7 +11,6 @@ import (
)

func TestOrganizeImportsPathsUnicode3(t *testing.T) {
fourslash.SkipIfFailing(t)
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `import * as B from "./B";
Expand All @@ -25,8 +21,8 @@ console.log(A, À, B);`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyOrganizeImports(t,
`import * as À from "./À";
import * as A from "./A";
`import * as A from "./A";
import * as À from "./À";
import * as B from "./B";

console.log(A, À, B);`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Code generated by convertFourslash; DO NOT EDIT.
// To modify this test, run "npm run makemanual organizeImportsUnicode3"

package fourslash_test

import (
Expand All @@ -14,7 +11,6 @@ import (
)

func TestOrganizeImportsUnicode3(t *testing.T) {
fourslash.SkipIfFailing(t)
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `import {
Expand All @@ -28,8 +24,8 @@ console.log(A, À, B);`
defer done()
f.VerifyOrganizeImports(t,
`import {
À,
A,
À,
B,
} from './foo';

Expand Down
19 changes: 9 additions & 10 deletions internal/fourslash/tests/organizeImports_coalesceExports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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/ls/lsutil"
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
Expand All @@ -22,7 +21,7 @@ void 0;`
`export { B, default as M, a as n, Z as O, y } from "lib";
void 0;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -39,7 +38,7 @@ void 0;`
`export * from "lib";
void 0;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -58,7 +57,7 @@ void 0;`
export { x, z as y };
void 0;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -75,7 +74,7 @@ void 0;`
`export { x, y as z } from "lib";
void 0;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -96,7 +95,7 @@ export * from "lib";
export { y } from "lib";
void 0;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -116,7 +115,7 @@ void 0;`
export { z as default, q as w, x, w as y };
void 0;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -135,7 +134,7 @@ void 0;`
export { x as a, z as b, y } from "lib";
void 0;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -160,7 +159,7 @@ export { x };
export type { y };
void 0;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -181,6 +180,6 @@ type y = number;
export type { x, y };
void 0;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}
35 changes: 17 additions & 18 deletions internal/fourslash/tests/organizeImports_coalesceImports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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/ls/lsutil"
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
Expand All @@ -22,7 +21,7 @@ M; n; B; y; O;`
`import { B, default as M, a as n, Z as O, y } from "lib";
M; n; B; y; O;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -39,7 +38,7 @@ void 0;`
`import "lib";
void 0;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -60,7 +59,7 @@ import * as x from "lib";
import * as y from "lib";
x; y; z;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -77,7 +76,7 @@ x; y;`
`import { default as x, default as y } from "lib";
x; y;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -94,7 +93,7 @@ x; z;`
`import { x, y as z } from "lib";
x; z;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -115,7 +114,7 @@ import "lib";
import * as x from "lib";
x; z;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -136,7 +135,7 @@ import "lib";
import x from "lib";
x; z;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -157,7 +156,7 @@ import "lib";
import { x } from "lib";
x; z;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -175,7 +174,7 @@ x; y;`
`import y, * as x from "lib";
x; y;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -196,7 +195,7 @@ import * as x from "lib";
import { y } from "lib";
x; y; z;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -214,7 +213,7 @@ x; y;`
`import x, { y } from "lib";
x; y;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -240,7 +239,7 @@ import * as y from "lib";
import { a, b, default as w, default as z } from "lib";
w; x; y; z; a; b;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -263,7 +262,7 @@ import * as y from "lib";
import z from "lib";
x; y; z; w;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -283,7 +282,7 @@ x; y; z;`
import { z } from "lib";
x; y; z;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -304,7 +303,7 @@ import type z from "lib";
import type { x } from "lib";
x; y; z;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -321,8 +320,8 @@ z; y; x; c; b; a;`
z; y; x; c; b; a;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{
OrganizeImportsIgnoreCase: core.TSTrue,
OrganizeImportsTypeOrder: lsutil.OrganizeImportsTypeOrderInline,
OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase,
OrganizeImportsTypeOrder: lsutil.OrganizeImportsTypeOrderInline,
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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/ls/lsutil"
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
Expand All @@ -24,7 +23,7 @@ x; y;`
import x from "lib2";
x; y;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -42,7 +41,7 @@ x; y;`
import x from "./lib2";
x; y;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -60,7 +59,7 @@ x; y;`
import x from "./lib";
x; y;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -79,7 +78,7 @@ x; y;`
import x from "Z";
x; y;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}

Expand All @@ -98,6 +97,6 @@ x; y;`
import x from "z";
x; y;`,
lsproto.CodeActionKindSourceSortImports,
&lsutil.UserPreferences{OrganizeImportsIgnoreCase: core.TSTrue},
&lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase},
)
}
Loading