Skip to content

Commit 186e6d5

Browse files
committed
Merge branch 'main' of https://github.com/microsoft/typescript-go into userpreferences
2 parents ff140e9 + 9ba3656 commit 186e6d5

File tree

2,704 files changed

+107560
-26174
lines changed

Some content is hidden

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

2,704 files changed

+107560
-26174
lines changed

.github/actions/setup-go/action.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ runs:
1818
steps:
1919
- name: Install Go
2020
id: install-go
21-
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
21+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
2222
with:
2323
go-version: ${{ inputs.go-version }}
2424
cache: false
@@ -39,15 +39,15 @@ runs:
3939
4040
- if: ${{ inputs.create != 'true' }}
4141
name: Restore Go modules
42-
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
42+
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
4343
with:
4444
key: ${{ steps.cache-info.outputs.modules-key }}
4545
path: |
4646
~/go/pkg/mod
4747
4848
- if: ${{ inputs.create != 'true' }}
4949
name: Restore Go build cache
50-
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
50+
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
5151
with:
5252
key: unused-key-${{ github.run_id }}
5353
restore-keys: ${{ steps.cache-info.outputs.build-key }}-
@@ -58,7 +58,7 @@ runs:
5858
5959
- if: ${{ inputs.create != 'true' && inputs.lint-cache == 'true' }}
6060
name: Restore golangci-lint cache
61-
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
61+
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
6262
with:
6363
key: unused-key-${{ github.run_id }}
6464
restore-keys: ${{ steps.cache-info.outputs.lint-key }}-
@@ -114,15 +114,15 @@ runs:
114114

115115
- if: ${{ inputs.create == 'true' }}
116116
name: Save Go modules
117-
uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
117+
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
118118
with:
119119
key: ${{ steps.cache-info.outputs.modules-key }}
120120
path: |
121121
~/go/pkg/mod
122122
123123
- if: ${{ inputs.create == 'true' }}
124124
name: Save Go build cache
125-
uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
125+
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
126126
with:
127127
key: ${{ steps.cache-info.outputs.build-key }}-${{ github.run_id }}
128128
path: |
@@ -132,7 +132,7 @@ runs:
132132
133133
- if: ${{ inputs.create == 'true' }}
134134
name: Save golangci-lint cache
135-
uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
135+
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
136136
with:
137137
key: ${{ steps.cache-info.outputs.lint-key }}-${{ github.run_id }}
138138
path: ${{ env.GOLANGCI_LINT_CACHE }}

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848

4949
# Initializes the CodeQL tools for scanning.
5050
- name: Initialize CodeQL
51-
uses: github/codeql-action/init@f1f6e5f6af878fb37288ce1c627459e94dbf7d01 # v3.29.5
51+
uses: github/codeql-action/init@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.29.5
5252
with:
5353
config-file: ./.github/codeql/codeql-configuration.yml
5454
# Override language selection by uncommenting this and choosing your languages
@@ -58,7 +58,7 @@ jobs:
5858
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5959
# If this step fails, then you should remove it and run the build manually (see below).
6060
- name: Autobuild
61-
uses: github/codeql-action/autobuild@f1f6e5f6af878fb37288ce1c627459e94dbf7d01 # v3.29.5
61+
uses: github/codeql-action/autobuild@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.29.5
6262

6363
# ℹ️ Command-line programs to run using the OS shell.
6464
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -72,4 +72,4 @@ jobs:
7272
# make release
7373

7474
- name: Perform CodeQL Analysis
75-
uses: github/codeql-action/analyze@f1f6e5f6af878fb37288ce1c627459e94dbf7d01 # v3.29.5
75+
uses: github/codeql-action/analyze@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.29.5

_extension/src/client.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ export class Client {
8181
};
8282
}
8383

84-
async initialize(context: vscode.ExtensionContext): Promise<void> {
84+
async initialize(context: vscode.ExtensionContext): Promise<vscode.Disposable> {
8585
const exe = await getExe(context);
86-
this.start(context, exe);
86+
return this.start(context, exe);
8787
}
8888

89-
async start(context: vscode.ExtensionContext, exe: { path: string; version: string; }): Promise<void> {
89+
async start(context: vscode.ExtensionContext, exe: { path: string; version: string; }): Promise<vscode.Disposable> {
9090
this.exe = exe;
9191
this.outputChannel.appendLine(`Resolved to ${this.exe.path}`);
9292

@@ -119,14 +119,12 @@ export class Client {
119119
await this.client.start();
120120
vscode.commands.executeCommand("setContext", "typescript.native-preview.serverRunning", true);
121121
this.onStartedCallbacks.forEach(callback => callback());
122-
context.subscriptions.push(
123-
new vscode.Disposable(() => {
124-
if (this.client) {
125-
this.client.stop();
126-
}
127-
vscode.commands.executeCommand("setContext", "typescript.native-preview.serverRunning", false);
128-
}),
129-
);
122+
return new vscode.Disposable(() => {
123+
if (this.client) {
124+
this.client.stop();
125+
}
126+
vscode.commands.executeCommand("setContext", "typescript.native-preview.serverRunning", false);
127+
});
130128
}
131129

132130
getCurrentExe(): { path: string; version: string; } | undefined {
@@ -145,7 +143,7 @@ export class Client {
145143
});
146144
}
147145

148-
async restart(context: vscode.ExtensionContext): Promise<void> {
146+
async restart(context: vscode.ExtensionContext): Promise<vscode.Disposable> {
149147
if (!this.client) {
150148
return Promise.reject(new Error("Language client is not initialized"));
151149
}
@@ -157,6 +155,7 @@ export class Client {
157155
}
158156

159157
this.outputChannel.appendLine(`Restarting language server...`);
160-
return this.client.restart();
158+
this.client.restart();
159+
return new vscode.Disposable(() => {});
161160
}
162161
}

_extension/src/commands.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as vscode from "vscode";
22
import { Client } from "./client";
3+
import { restartExtHostOnChangeIfNeeded } from "./util";
34

4-
export function registerCommands(context: vscode.ExtensionContext, client: Client, outputChannel: vscode.OutputChannel, traceOutputChannel: vscode.OutputChannel): void {
5+
export function registerEnablementCommands(context: vscode.ExtensionContext): void {
56
context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.enable", () => {
67
// Fire and forget, because this will restart the extension host and cause an error if we await
78
updateUseTsgoSetting(true);
@@ -11,23 +12,29 @@ export function registerCommands(context: vscode.ExtensionContext, client: Clien
1112
// Fire and forget, because this will restart the extension host and cause an error if we await
1213
updateUseTsgoSetting(false);
1314
}));
15+
}
16+
17+
export function registerLanguageCommands(context: vscode.ExtensionContext, client: Client, outputChannel: vscode.OutputChannel, traceOutputChannel: vscode.OutputChannel): vscode.Disposable[] {
18+
const disposables: vscode.Disposable[] = [];
1419

15-
context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.restart", () => {
20+
disposables.push(vscode.commands.registerCommand("typescript.native-preview.restart", () => {
1621
return client.restart(context);
1722
}));
1823

19-
context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.output.focus", () => {
24+
disposables.push(vscode.commands.registerCommand("typescript.native-preview.output.focus", () => {
2025
outputChannel.show();
2126
}));
2227

23-
context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.lsp-trace.focus", () => {
28+
disposables.push(vscode.commands.registerCommand("typescript.native-preview.lsp-trace.focus", () => {
2429
traceOutputChannel.show();
2530
}));
2631

27-
context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.selectVersion", async () => {
32+
disposables.push(vscode.commands.registerCommand("typescript.native-preview.selectVersion", async () => {
2833
}));
2934

30-
context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.showMenu", showCommands));
35+
disposables.push(vscode.commands.registerCommand("typescript.native-preview.showMenu", showCommands));
36+
37+
return disposables;
3138
}
3239

3340
/**
@@ -44,7 +51,7 @@ async function updateUseTsgoSetting(enable: boolean): Promise<void> {
4451
}
4552
// Update the setting and restart the extension host (needed to change the state of the built-in TS extension)
4653
await tsConfig.update("experimental.useTsgo", enable, target);
47-
await vscode.commands.executeCommand("workbench.action.restartExtensionHost");
54+
await restartExtHostOnChangeIfNeeded();
4855
}
4956

5057
/**

_extension/src/extension.ts

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
11
import * as vscode from "vscode";
22

33
import { Client } from "./client";
4-
import { registerCommands } from "./commands";
4+
import {
5+
registerEnablementCommands,
6+
registerLanguageCommands,
7+
} from "./commands";
58
import { setupStatusBar } from "./statusBar";
9+
import { needsExtHostRestartOnChange } from "./util";
610
import { setupVersionStatusItem } from "./versionStatusItem";
711

812
export async function activate(context: vscode.ExtensionContext) {
913
await vscode.commands.executeCommand("setContext", "typescript.native-preview.serverRunning", false);
10-
14+
registerEnablementCommands(context);
1115
const output = vscode.window.createOutputChannel("typescript-native-preview", "log");
1216
const traceOutput = vscode.window.createOutputChannel("typescript-native-preview (LSP)");
13-
const client = new Client(output, traceOutput);
14-
registerCommands(context, client, output, traceOutput);
17+
context.subscriptions.push(output, traceOutput);
1518

16-
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(event => {
19+
let disposeLanguageFeatures: vscode.Disposable | undefined;
20+
21+
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async event => {
1722
if (event.affectsConfiguration("typescript.experimental.useTsgo")) {
18-
// Delay because the command to change the config setting will restart
19-
// the extension host, so no need to show a message
20-
setTimeout(async () => {
21-
const selected = await vscode.window.showInformationMessage("TypeScript Native Preview setting has changed. Restart extensions to apply changes.", "Restart Extensions");
22-
if (selected) {
23-
vscode.commands.executeCommand("workbench.action.restartExtensionHost");
23+
if (needsExtHostRestartOnChange()) {
24+
// Delay because the command to change the config setting will restart
25+
// the extension host, so no need to show a message
26+
setTimeout(async () => {
27+
const selected = await vscode.window.showInformationMessage("TypeScript Native Preview setting has changed. Restart extensions to apply changes.", "Restart Extensions");
28+
if (selected) {
29+
vscode.commands.executeCommand("workbench.action.restartExtensionHost");
30+
}
31+
}, 100);
32+
}
33+
else {
34+
const useTsgo = vscode.workspace.getConfiguration("typescript").get<boolean>("experimental.useTsgo");
35+
if (useTsgo) {
36+
disposeLanguageFeatures = await activateLanguageFeatures(context, output, traceOutput);
37+
context.subscriptions.push(disposeLanguageFeatures);
2438
}
25-
}, 100);
39+
else {
40+
disposeLanguageFeatures?.dispose();
41+
disposeLanguageFeatures = undefined;
42+
}
43+
}
2644
}
2745
}));
2846

@@ -41,10 +59,17 @@ export async function activate(context: vscode.ExtensionContext) {
4159
}
4260
}
4361

44-
await client.initialize(context);
45-
setupStatusBar(context);
46-
setupVersionStatusItem(context, client);
62+
disposeLanguageFeatures = await activateLanguageFeatures(context, output, traceOutput);
63+
context.subscriptions.push(disposeLanguageFeatures);
4764
}
4865

49-
export async function deactivate(): Promise<void> {
66+
async function activateLanguageFeatures(context: vscode.ExtensionContext, output: vscode.OutputChannel, traceOutput: vscode.OutputChannel): Promise<vscode.Disposable> {
67+
const disposables: vscode.Disposable[] = [];
68+
69+
const client = new Client(output, traceOutput);
70+
disposables.push(...registerLanguageCommands(context, client, output, traceOutput));
71+
disposables.push(await client.initialize(context));
72+
disposables.push(setupStatusBar());
73+
disposables.push(...setupVersionStatusItem(client));
74+
return vscode.Disposable.from(...disposables);
5075
}

_extension/src/statusBar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as vscode from "vscode";
22

3-
export function setupStatusBar(context: vscode.ExtensionContext): void {
3+
export function setupStatusBar(): vscode.Disposable {
44
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
55
statusBarItem.text = "$(beaker) tsgo";
66
statusBarItem.tooltip = "TypeScript Native Preview Language Server";
77
statusBarItem.command = "typescript.native-preview.showMenu";
88
statusBarItem.backgroundColor = new vscode.ThemeColor("statusBarItem.warningBackground");
99
statusBarItem.show();
10-
context.subscriptions.push(statusBarItem);
10+
return statusBarItem;
1111
}

_extension/src/util.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,15 @@ export function getLanguageForUri(uri: vscode.Uri): string | undefined {
8989
return undefined;
9090
}
9191
}
92+
93+
export function needsExtHostRestartOnChange() {
94+
const majorVersion = parseInt(vscode.version.split(".")[0]);
95+
const minorVersion = parseInt(vscode.version.split(".")[1]);
96+
return majorVersion <= 1 && minorVersion < 105;
97+
}
98+
99+
export async function restartExtHostOnChangeIfNeeded(): Promise<void> {
100+
if (needsExtHostRestartOnChange()) {
101+
await vscode.commands.executeCommand("workbench.action.restartExtensionHost");
102+
}
103+
}

_extension/src/versionStatusItem.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { Client } from "./client";
33
import { jsTsLanguageModes } from "./util";
44

55
export function setupVersionStatusItem(
6-
context: vscode.ExtensionContext,
76
client: Client,
8-
): void {
7+
): vscode.Disposable[] {
98
const statusItem = vscode.languages.createLanguageStatusItem("typescript.native-preview.version", jsTsLanguageModes);
109
statusItem.name = "TypeScript Native Preview version";
1110
statusItem.detail = "TypeScript Native Preview version";
12-
context.subscriptions.push(client.onStarted(() => {
13-
statusItem.text = client.getCurrentExe()!.version;
14-
}));
15-
context.subscriptions.push(statusItem);
11+
return [
12+
statusItem,
13+
client.onStarted(() => {
14+
statusItem.text = client.getCurrentExe()!.version;
15+
}),
16+
];
1617
}

_submodules/TypeScript

Submodule TypeScript updated 1509 files

internal/api/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (api *API) GetSymbolAtPosition(ctx context.Context, projectId Handle[projec
160160
return nil, errors.New("project not found")
161161
}
162162

163-
languageService := ls.NewLanguageService(project, snapshot.Converters(), snapshot.UserPreferences())
163+
languageService := ls.NewLanguageService(project.GetProgram(), snapshot)
164164
symbol, err := languageService.GetSymbolAtPosition(ctx, fileName, position)
165165
if err != nil || symbol == nil {
166166
return nil, err
@@ -202,7 +202,7 @@ func (api *API) GetSymbolAtLocation(ctx context.Context, projectId Handle[projec
202202
if node == nil {
203203
return nil, fmt.Errorf("node of kind %s not found at position %d in file %q", kind.String(), pos, sourceFile.FileName())
204204
}
205-
languageService := ls.NewLanguageService(project, snapshot.Converters(), snapshot.UserPreferences())
205+
languageService := ls.NewLanguageService(project.GetProgram(), snapshot)
206206
symbol := languageService.GetSymbolAtLocation(ctx, node)
207207
if symbol == nil {
208208
return nil, nil
@@ -232,7 +232,7 @@ func (api *API) GetTypeOfSymbol(ctx context.Context, projectId Handle[project.Pr
232232
if !ok {
233233
return nil, fmt.Errorf("symbol %q not found", symbolHandle)
234234
}
235-
languageService := ls.NewLanguageService(project, snapshot.Converters(), snapshot.UserPreferences())
235+
languageService := ls.NewLanguageService(project.GetProgram(), snapshot)
236236
t := languageService.GetTypeOfSymbol(ctx, symbol)
237237
if t == nil {
238238
return nil, nil

0 commit comments

Comments
 (0)