Skip to content

Commit 9a62fef

Browse files
committed
Merge branch 'main' into jabaile/lsp-fs-cache
2 parents a68ac74 + 7bcea23 commit 9a62fef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4358
-379
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{
1818
"label": "Watch",
1919
"type": "npm",
20-
"script": "build:watch",
20+
"script": "build:watch:debug",
2121
"group": "build",
2222
"presentation": {
2323
"panel": "dedicated",

Herebyfile.mjs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,7 @@ const { values: rawOptions } = parseArgs({
7575

7676
// We can't use parseArgs' strict mode as it errors on hereby's --tasks flag.
7777
/**
78-
* @typedef {{ [K in keyof T as {} extends Record<K, 1> ? never : K]: T[K] }} RemoveIndex<T>
79-
* @template T
80-
*/
81-
/**
82-
* @typedef {RemoveIndex<typeof rawOptions>} Options
78+
* @typedef {{ [K in keyof typeof rawOptions as {} extends Record<K, 1> ? never : K]: typeof rawOptions[K] }} Options
8379
*/
8480
const options = /** @type {Options} */ (rawOptions);
8581

@@ -107,9 +103,12 @@ const goBuildFlags = [
107103
];
108104

109105
/**
110-
* @type {<T>(fn: () => T) => (() => T)}
106+
* @template T
107+
* @param {() => T} fn
108+
* @returns {() => T}
111109
*/
112110
function memoize(fn) {
111+
/** @type {T} */
113112
let value;
114113
return () => {
115114
if (fn !== undefined) {
@@ -842,21 +841,20 @@ const mainNativePreviewPackage = {
842841
* @typedef {"win32" | "linux" | "darwin"} OS
843842
* @typedef {"x64" | "arm" | "arm64"} Arch
844843
* @typedef {"Microsoft400" | "LinuxSign" | "MacDeveloperHarden" | "8020" | "VSCodePublisher"} Cert
845-
* @typedef {`${OS}-${Exclude<Arch, "arm"> | "armhf"}`} VSCodeTarget
844+
* @typedef {`${OS | "alpine"}-${Exclude<Arch, "arm"> | "armhf"}`} VSCodeTarget
846845
*/
847846
void 0;
848847

849848
const nativePreviewPlatforms = memoize(() => {
850-
/** @type {[OS, Arch, Cert][]} */
849+
/** @type {[os: OS, arch: Arch, cert: Cert, alpine?: boolean][]} */
851850
let supportedPlatforms = [
852851
["win32", "x64", "Microsoft400"],
853852
["win32", "arm64", "Microsoft400"],
854-
["linux", "x64", "LinuxSign"],
853+
["linux", "x64", "LinuxSign", true],
855854
["linux", "arm", "LinuxSign"],
856-
["linux", "arm64", "LinuxSign"],
855+
["linux", "arm64", "LinuxSign", true],
857856
["darwin", "x64", "MacDeveloperHarden"],
858857
["darwin", "arm64", "MacDeveloperHarden"],
859-
// Alpine?
860858
// Wasm?
861859
];
862860

@@ -865,17 +863,32 @@ const nativePreviewPlatforms = memoize(() => {
865863
assert.equal(supportedPlatforms.length, 1, "No supported platforms found");
866864
}
867865

868-
return supportedPlatforms.map(([os, arch, cert]) => {
866+
return supportedPlatforms.map(([os, arch, cert, alpine]) => {
869867
const npmDirName = `native-preview-${os}-${arch}`;
870868
const npmDir = path.join(builtNpm, npmDirName);
871869
const npmTarball = `${npmDir}.tgz`;
872870
const npmPackageName = `@typescript/${npmDirName}`;
873-
/** @type {VSCodeTarget} */
874-
const vscodeTarget = `${os}-${arch === "arm" ? "armhf" : arch}`;
875-
const extensionDir = path.join(builtVsix, `typescript-native-preview-${vscodeTarget}`);
876-
const vsixPath = extensionDir + ".vsix";
877-
const vsixManifestPath = extensionDir + ".manifest";
878-
const vsixSignaturePath = extensionDir + ".signature.p7s";
871+
872+
/** @type {VSCodeTarget[]} */
873+
const vscodeTargets = [`${os}-${arch === "arm" ? "armhf" : arch}`];
874+
if (alpine) {
875+
vscodeTargets.push(`alpine-${arch === "arm" ? "armhf" : arch}`);
876+
}
877+
878+
const extensions = vscodeTargets.map(vscodeTarget => {
879+
const extensionDir = path.join(builtVsix, `typescript-native-preview-${vscodeTarget}`);
880+
const vsixPath = extensionDir + ".vsix";
881+
const vsixManifestPath = extensionDir + ".manifest";
882+
const vsixSignaturePath = extensionDir + ".signature.p7s";
883+
return {
884+
vscodeTarget,
885+
extensionDir,
886+
vsixPath,
887+
vsixManifestPath,
888+
vsixSignaturePath,
889+
};
890+
});
891+
879892
return {
880893
nodeOs: os,
881894
nodeArch: arch,
@@ -885,11 +898,7 @@ const nativePreviewPlatforms = memoize(() => {
885898
npmDirName,
886899
npmDir,
887900
npmTarball,
888-
vscodeTarget,
889-
extensionDir,
890-
vsixPath,
891-
vsixManifestPath,
892-
vsixSignaturePath,
901+
extensions,
893902
cert,
894903
};
895904
});
@@ -1040,6 +1049,7 @@ export const signNativePreviewPackages = task({
10401049
SignFileRecordList: [],
10411050
};
10421051

1052+
/** @type {{ path: string; unsignedZipPath: string; signedZipPath: string; notarizedZipPath: string; }[]} */
10431053
const macZips = [];
10441054

10451055
// First, sign the files.
@@ -1175,8 +1185,9 @@ export const packNativePreviewExtensions = task({
11751185
console.log("Version:", version);
11761186

11771187
const platforms = nativePreviewPlatforms();
1188+
const extensions = platforms.flatMap(({ npmDir, extensions }) => extensions.map(e => ({ npmDir, ...e })));
11781189

1179-
await Promise.all(platforms.map(async ({ npmDir, vscodeTarget, extensionDir: thisExtensionDir, vsixPath, vsixManifestPath, vsixSignaturePath }) => {
1190+
await Promise.all(extensions.map(async ({ npmDir, vscodeTarget, extensionDir: thisExtensionDir, vsixPath, vsixManifestPath, vsixSignaturePath }) => {
11801191
const npmLibDir = path.join(npmDir, "lib");
11811192
const extensionLibDir = path.join(thisExtensionDir, "lib");
11821193
await fs.promises.mkdir(extensionLibDir, { recursive: true });
@@ -1211,10 +1222,12 @@ export const signNativePreviewExtensions = task({
12111222
}
12121223

12131224
const platforms = nativePreviewPlatforms();
1225+
const extensions = platforms.flatMap(({ npmDir, extensions }) => extensions.map(e => ({ npmDir, ...e })));
1226+
12141227
await sign({
12151228
SignFileRecordList: [
12161229
{
1217-
SignFileList: platforms.map(({ vsixSignaturePath }) => ({ SrcPath: vsixSignaturePath, DstPath: null })),
1230+
SignFileList: extensions.map(({ vsixSignaturePath }) => ({ SrcPath: vsixSignaturePath, DstPath: null })),
12181231
Certs: "VSCodePublisher",
12191232
},
12201233
],
@@ -1244,7 +1257,7 @@ export const installExtension = task({
12441257
throw new Error(`No platform found for ${process.platform}-${process.arch}`);
12451258
}
12461259

1247-
await $`${options.insiders ? "code-insiders" : "code"} --install-extension ${myPlatform.vsixPath}`;
1260+
await $`${options.insiders ? "code-insiders" : "code"} --install-extension ${myPlatform.extensions[0].vsixPath}`;
12481261
console.log(pc.yellowBright("\nExtension installed. ") + "To enable this extension, set:\n");
12491262
console.log(pc.whiteBright(` "typescript.experimental.useTsgo": true\n`));
12501263
console.log("To configure the extension to use built/local instead of its bundled tsgo, set:\n");

_extension/src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { setupStatusBar } from "./statusBar";
66
import { setupVersionStatusItem } from "./versionStatusItem";
77

88
export async function activate(context: vscode.ExtensionContext) {
9+
await vscode.commands.executeCommand("setContext", "typescript.native-preview.serverRunning", false);
10+
911
const output = vscode.window.createOutputChannel("typescript-native-preview", "log");
1012
const traceOutput = vscode.window.createOutputChannel("typescript-native-preview (LSP)");
1113
const client = new Client(output, traceOutput);

cmd/tsgo/lsp.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import (
44
"flag"
55
"fmt"
66
"os"
7+
"runtime"
78

89
"github.com/microsoft/typescript-go/internal/bundled"
910
"github.com/microsoft/typescript-go/internal/core"
1011
"github.com/microsoft/typescript-go/internal/lsp"
1112
"github.com/microsoft/typescript-go/internal/pprof"
13+
"github.com/microsoft/typescript-go/internal/tspath"
1214
"github.com/microsoft/typescript-go/internal/vfs/osvfs"
1315
)
1416

@@ -37,6 +39,7 @@ func runLSP(args []string) int {
3739

3840
fs := bundled.WrapFS(osvfs.FS())
3941
defaultLibraryPath := bundled.LibPath()
42+
typingsLocation := getGlobalTypingsCacheLocation()
4043

4144
s := lsp.NewServer(&lsp.ServerOptions{
4245
In: os.Stdin,
@@ -45,10 +48,78 @@ func runLSP(args []string) int {
4548
Cwd: core.Must(os.Getwd()),
4649
FS: fs,
4750
DefaultLibraryPath: defaultLibraryPath,
51+
TypingsLocation: typingsLocation,
4852
})
4953

5054
if err := s.Run(); err != nil {
5155
return 1
5256
}
5357
return 0
5458
}
59+
60+
func getGlobalTypingsCacheLocation() string {
61+
switch runtime.GOOS {
62+
case "windows":
63+
return tspath.CombinePaths(tspath.CombinePaths(getWindowsCacheLocation(), "Microsoft/TypeScript"), core.VersionMajorMinor())
64+
case "openbsd", "freebsd", "netbsd", "darwin", "linux", "android":
65+
return tspath.CombinePaths(tspath.CombinePaths(getNonWindowsCacheLocation(), "typescript"), core.VersionMajorMinor())
66+
default:
67+
panic("unsupported platform: " + runtime.GOOS)
68+
}
69+
}
70+
71+
func getWindowsCacheLocation() string {
72+
basePath, err := os.UserCacheDir()
73+
if err != nil {
74+
if basePath, err = os.UserConfigDir(); err != nil {
75+
if basePath, err = os.UserHomeDir(); err != nil {
76+
if userProfile := os.Getenv("USERPROFILE"); userProfile != "" {
77+
basePath = userProfile
78+
} else if homeDrive, homePath := os.Getenv("HOMEDRIVE"), os.Getenv("HOMEPATH"); homeDrive != "" && homePath != "" {
79+
basePath = homeDrive + homePath
80+
} else {
81+
basePath = os.TempDir()
82+
}
83+
}
84+
}
85+
}
86+
return basePath
87+
}
88+
89+
func getNonWindowsCacheLocation() string {
90+
if xdgCacheHome := os.Getenv("XDG_CACHE_HOME"); xdgCacheHome != "" {
91+
return xdgCacheHome
92+
}
93+
const platformIsDarwin = runtime.GOOS == "darwin"
94+
var usersDir string
95+
if platformIsDarwin {
96+
usersDir = "Users"
97+
} else {
98+
usersDir = "home"
99+
}
100+
homePath, err := os.UserHomeDir()
101+
if err != nil {
102+
if home := os.Getenv("HOME"); home != "" {
103+
homePath = home
104+
} else {
105+
var userName string
106+
if logName := os.Getenv("LOGNAME"); logName != "" {
107+
userName = logName
108+
} else if user := os.Getenv("USER"); user != "" {
109+
userName = user
110+
}
111+
if userName != "" {
112+
homePath = "/" + usersDir + "/" + userName
113+
} else {
114+
homePath = os.TempDir()
115+
}
116+
}
117+
}
118+
var cacheFolder string
119+
if platformIsDarwin {
120+
cacheFolder = "Library/Caches"
121+
} else {
122+
cacheFolder = ".cache"
123+
}
124+
return tspath.CombinePaths(homePath, cacheFolder)
125+
}

internal/api/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ func (api *API) DefaultLibraryPath() string {
7373
return api.host.DefaultLibraryPath()
7474
}
7575

76+
// TypingsInstaller implements ProjectHost
77+
func (api *API) TypingsInstaller() *project.TypingsInstaller {
78+
return nil
79+
}
80+
7681
// DocumentRegistry implements ProjectHost.
7782
func (api *API) DocumentRegistry() *project.DocumentRegistry {
7883
return api.documentRegistry

internal/checker/checker.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18114,7 +18114,7 @@ func (c *Checker) areAllOuterTypeParametersApplied(t *Type) bool {
1811418114
}
1811518115

1811618116
func (c *Checker) reportCircularBaseType(node *ast.Node, t *Type) {
18117-
c.error(node, diagnostics.Type_0_recursively_references_itself_as_a_base_type, c.typeToStringEx(t, nil, TypeFormatFlagsWriteArrayAsGenericType, nil))
18117+
c.error(node, diagnostics.Type_0_recursively_references_itself_as_a_base_type, c.typeToStringEx(t, nil, TypeFormatFlagsWriteArrayAsGenericType))
1811818118
}
1811918119

1812018120
// A valid base type is `any`, an object type or intersection of object types.
@@ -20387,11 +20387,11 @@ func (c *Checker) elaborateNeverIntersection(chain *ast.Diagnostic, node *ast.No
2038720387
if t.flags&TypeFlagsIntersection != 0 && t.objectFlags&ObjectFlagsIsNeverIntersection != 0 {
2038820388
neverProp := core.Find(c.getPropertiesOfUnionOrIntersectionType(t), c.isDiscriminantWithNeverType)
2038920389
if neverProp != nil {
20390-
return NewDiagnosticChainForNode(chain, node, diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_has_conflicting_types_in_some_constituents, c.typeToStringEx(t, nil, TypeFormatFlagsNoTypeReduction, nil), c.symbolToString(neverProp))
20390+
return NewDiagnosticChainForNode(chain, node, diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_has_conflicting_types_in_some_constituents, c.typeToStringEx(t, nil, TypeFormatFlagsNoTypeReduction), c.symbolToString(neverProp))
2039120391
}
2039220392
privateProp := core.Find(c.getPropertiesOfUnionOrIntersectionType(t), isConflictingPrivateProperty)
2039320393
if privateProp != nil {
20394-
return NewDiagnosticChainForNode(chain, node, diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_exists_in_multiple_constituents_and_is_private_in_some, c.typeToStringEx(t, nil, TypeFormatFlagsNoTypeReduction, nil), c.symbolToString(privateProp))
20394+
return NewDiagnosticChainForNode(chain, node, diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_exists_in_multiple_constituents_and_is_private_in_some, c.typeToStringEx(t, nil, TypeFormatFlagsNoTypeReduction), c.symbolToString(privateProp))
2039520395
}
2039620396
}
2039720397
return chain

0 commit comments

Comments
 (0)