Skip to content

Commit 20b31f7

Browse files
nathanwhitdsherret
authored andcommitted
Deno changes
1 parent d1be94b commit 20b31f7

Some content is hidden

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

54 files changed

+2242
-793
lines changed

.github/workflows/ci.yml

Lines changed: 334 additions & 347 deletions
Large diffs are not rendered by default.

.github/workflows/create-cache.yml

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
name: Create CI cache
2-
3-
on:
4-
workflow_dispatch:
5-
push:
6-
branches:
7-
- main
8-
schedule:
9-
# Run every day at 10:00 UTC / 03:00 PST
10-
- cron: '0 10 * * *'
11-
12-
permissions:
13-
contents: read
14-
15-
# Ensure scripts are run with pipefail. See:
16-
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
17-
defaults:
18-
run:
19-
shell: bash
20-
21-
jobs:
22-
cache:
23-
if: github.repository == 'microsoft/typescript-go'
24-
25-
strategy:
26-
fail-fast: false
27-
matrix:
28-
os:
29-
- ubuntu-latest
30-
- windows-latest
31-
- macos-latest
32-
33-
runs-on: ${{ matrix.os }}
34-
35-
steps:
36-
- uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
37-
with:
38-
large-packages: false
39-
docker-images: false
40-
swap-storage: false
41-
dotnet: false
42-
43-
- run: git config --system core.longpaths true
44-
if: ${{ matrix.os == 'windows-latest' }}
45-
46-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
47-
with:
48-
submodules: true
49-
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
50-
- uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable
51-
52-
- uses: ./.github/actions/setup-go
53-
with:
54-
create: 'true'
1+
# name: Create CI cache
2+
3+
# on:
4+
# workflow_dispatch:
5+
# push:
6+
# branches:
7+
# - main
8+
# schedule:
9+
# # Run every day at 10:00 UTC / 03:00 PST
10+
# - cron: '0 10 * * *'
11+
12+
# permissions:
13+
# contents: read
14+
15+
# # Ensure scripts are run with pipefail. See:
16+
# # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
17+
# defaults:
18+
# run:
19+
# shell: bash
20+
21+
# jobs:
22+
# cache:
23+
# if: github.repository == 'microsoft/typescript-go'
24+
25+
# strategy:
26+
# fail-fast: false
27+
# matrix:
28+
# os:
29+
# - ubuntu-latest
30+
# - windows-latest
31+
# - macos-latest
32+
33+
# runs-on: ${{ matrix.os }}
34+
35+
# steps:
36+
# - uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
37+
# with:
38+
# large-packages: false
39+
# docker-images: false
40+
# swap-storage: false
41+
# dotnet: false
42+
43+
# - run: git config --system core.longpaths true
44+
# if: ${{ matrix.os == 'windows-latest' }}
45+
46+
# - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
47+
# with:
48+
# submodules: true
49+
# - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
50+
# - uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable
51+
52+
# - uses: ./.github/actions/setup-go
53+
# with:
54+
# create: 'true'

.github/workflows/release.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
defaults:
12+
run:
13+
shell: bash
14+
15+
jobs:
16+
build:
17+
name: Build ${{ matrix.archive_suffix }}
18+
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
include:
23+
- goos: linux
24+
goarch: amd64
25+
archive_suffix: linux-x64
26+
binary_name: tsgo
27+
- goos: linux
28+
goarch: arm64
29+
archive_suffix: linux-arm64
30+
binary_name: tsgo
31+
- goos: darwin
32+
goarch: amd64
33+
archive_suffix: macos-x64
34+
binary_name: tsgo
35+
- goos: darwin
36+
goarch: arm64
37+
archive_suffix: macos-arm64
38+
binary_name: tsgo
39+
- goos: windows
40+
goarch: amd64
41+
archive_suffix: windows-x64
42+
binary_name: tsgo.exe
43+
44+
steps:
45+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
46+
47+
- uses: ./.github/actions/setup-go
48+
49+
- name: Determine version
50+
id: version
51+
run: |
52+
VERSION="${GITHUB_REF_NAME#v}"
53+
echo "version=$VERSION" >> $GITHUB_OUTPUT
54+
echo "VERSION=$VERSION" >> $GITHUB_ENV
55+
56+
- name: Build release archive
57+
id: package
58+
env:
59+
GOOS: ${{ matrix.goos }}
60+
GOARCH: ${{ matrix.goarch }}
61+
CGO_ENABLED: 0
62+
run: |
63+
set -euo pipefail
64+
65+
VERSION="${VERSION:?}"
66+
TARGET="typescript-go-${VERSION}-${{ matrix.archive_suffix }}"
67+
OUT_DIR="dist/${TARGET}"
68+
BIN_NAME="${{ matrix.binary_name }}"
69+
70+
mkdir -p "$OUT_DIR"
71+
72+
go build \
73+
-trimpath \
74+
-tags "noembed,release" \
75+
-ldflags "-s -w -X github.com/microsoft/typescript-go/internal/core.version=${VERSION}" \
76+
-o "$OUT_DIR/$BIN_NAME" \
77+
./cmd/tsgo
78+
79+
cp LICENSE "$OUT_DIR/"
80+
cp NOTICE.txt "$OUT_DIR/"
81+
82+
ARCHIVE_NAME="${TARGET}.zip"
83+
mkdir -p artifacts
84+
zip -9 -j "artifacts/${ARCHIVE_NAME}" "$OUT_DIR"/*
85+
86+
echo "archive-path=artifacts/${ARCHIVE_NAME}" >> "$GITHUB_OUTPUT"
87+
88+
- name: Upload release artifact
89+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
90+
with:
91+
name: tsgo-${{ matrix.archive_suffix }}-${{ steps.version.outputs.version }}
92+
path: ${{ steps.package.outputs.archive-path }}
93+
94+
publish:
95+
needs: build
96+
runs-on: ubuntu-latest
97+
steps:
98+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
99+
100+
- name: Download build artifacts
101+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
102+
with:
103+
path: release
104+
merge-multiple: true
105+
106+
- name: Create source archive
107+
run: |
108+
set -euo pipefail
109+
110+
RAW_TAG="${GITHUB_REF_NAME}"
111+
VERSION="${RAW_TAG#v}"
112+
ARCHIVE_FOLDER="typescript-go-${VERSION}"
113+
ARCHIVE_NAME="${ARCHIVE_FOLDER}-source.zip"
114+
TMP_DIR="$(mktemp -d)"
115+
SOURCE_DIR="${TMP_DIR}/${ARCHIVE_FOLDER}"
116+
117+
mkdir -p "${SOURCE_DIR}"
118+
119+
rsync -a \
120+
--exclude='.git/' \
121+
--exclude='release/' \
122+
--exclude='node_modules/' \
123+
--exclude='testdata/' \
124+
./ "${SOURCE_DIR}/"
125+
126+
mkdir -p release
127+
(cd "${TMP_DIR}" && zip -9 -r "${GITHUB_WORKSPACE}/release/${ARCHIVE_NAME}" "${ARCHIVE_FOLDER}")
128+
129+
- name: Create or update GitHub release
130+
env:
131+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133+
run: |
134+
set -euo pipefail
135+
136+
RAW_TAG="${GITHUB_REF_NAME}"
137+
VERSION="${RAW_TAG#v}"
138+
TITLE="TypeScript Go ${VERSION}"
139+
NOTES="Release ${VERSION}"
140+
REPO="${GITHUB_REPOSITORY}"
141+
142+
shopt -s nullglob
143+
ASSETS=(release/*.zip)
144+
if [ ${#ASSETS[@]} -eq 0 ]; then
145+
echo "No release assets found" >&2
146+
exit 1
147+
fi
148+
149+
if gh release view "$RAW_TAG" --repo "$REPO" >/dev/null 2>&1; then
150+
gh release edit "$RAW_TAG" --repo "$REPO" --title "$TITLE" --notes "$NOTES"
151+
gh release upload "$RAW_TAG" "${ASSETS[@]}" --repo "$REPO" --clobber
152+
else
153+
gh release create "$RAW_TAG" "${ASSETS[@]}" --repo "$REPO" --title "$TITLE" --notes "$NOTES" --latest --verify-tag
154+
fi

cmd/tsgo/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ func runAPI(args []string) int {
2121

2222
defaultLibraryPath := bundled.LibPath()
2323

24+
logEnabled := os.Getenv("TSGO_LOG_ENABLED") == "1"
25+
2426
s := api.NewServer(&api.ServerOptions{
2527
In: os.Stdin,
2628
Out: os.Stdout,
2729
Err: os.Stderr,
2830
Cwd: *cwd,
2931
DefaultLibraryPath: defaultLibraryPath,
32+
LogEnabled: logEnabled,
3033
})
3134

3235
if err := s.Run(); err != nil && !errors.Is(err, io.EOF) {

internal/api/api.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ func (api *API) HandleRequest(ctx context.Context, method string, payload []byte
105105
return encodeJSON(core.TryMap(params.Symbols, func(symbol Handle[ast.Symbol]) (any, error) {
106106
return api.GetTypeOfSymbol(ctx, params.Project, symbol)
107107
}))
108+
case MethodGetDiagnostics:
109+
params := params.(*GetDiagnosticsParams)
110+
return encodeJSON((api.GetDiagnostics(ctx, params.Project, params.FileNames)))
108111
default:
109112
return nil, fmt.Errorf("unhandled API method %q", method)
110113
}
@@ -262,6 +265,26 @@ func (api *API) GetSourceFile(projectId Handle[project.Project], fileName string
262265
return sourceFile, nil
263266
}
264267

268+
func (api *API) GetDiagnostics(ctx context.Context, projectId Handle[project.Project], fileNames []string) ([]*ls.Diagnostic, error) {
269+
projectPath, ok := api.projects[projectId]
270+
if !ok {
271+
return nil, errors.New("project ID not found")
272+
}
273+
snapshot, release := api.session.Snapshot()
274+
defer release()
275+
project := snapshot.ProjectCollection.GetProjectByPath(projectPath)
276+
if project == nil {
277+
return nil, errors.New("project not found")
278+
}
279+
280+
languageService := ls.NewLanguageService(project.GetProgram(), snapshot)
281+
diagnostics := languageService.GetDiagnostics(ctx, fileNames)
282+
283+
api.symbolsMu.Lock()
284+
defer api.symbolsMu.Unlock()
285+
return diagnostics, nil
286+
}
287+
265288
func (api *API) releaseHandle(handle string) error {
266289
switch handle[0] {
267290
case handlePrefixProject:
@@ -316,5 +339,9 @@ func encodeJSON(v any, err error) ([]byte, error) {
316339
if err != nil {
317340
return nil, err
318341
}
319-
return json.Marshal(v)
342+
b, err := json.Marshal(v)
343+
if err != nil {
344+
return nil, err
345+
}
346+
return b, nil
320347
}

internal/api/log.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package api
2+
3+
import "github.com/microsoft/typescript-go/internal/project/logging"
4+
5+
type NoLogger struct{}
6+
7+
// SetVerbose implements logging.Logger.
8+
func (n NoLogger) SetVerbose(verbose bool) {
9+
panic("unimplemented")
10+
}
11+
12+
var _ logging.Logger = (*NoLogger)(nil)
13+
14+
func (n NoLogger) Log(msg ...any) {}
15+
func (n NoLogger) Logf(format string, args ...any) {}
16+
func (n NoLogger) Write(msg string) {}
17+
func (n NoLogger) Verbose() logging.Logger {
18+
return n
19+
}
20+
21+
func (n NoLogger) IsVerbose() bool {
22+
return false
23+
}

internal/api/proto.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const (
8787
MethodGetTypeOfSymbol Method = "getTypeOfSymbol"
8888
MethodGetTypesOfSymbols Method = "getTypesOfSymbols"
8989
MethodGetSourceFile Method = "getSourceFile"
90+
MethodGetDiagnostics Method = "getDiagnostics"
9091
)
9192

9293
var unmarshalers = map[Method]func([]byte) (any, error){
@@ -100,11 +101,18 @@ var unmarshalers = map[Method]func([]byte) (any, error){
100101
MethodGetSymbolsAtLocations: unmarshallerFor[GetSymbolsAtLocationsParams],
101102
MethodGetTypeOfSymbol: unmarshallerFor[GetTypeOfSymbolParams],
102103
MethodGetTypesOfSymbols: unmarshallerFor[GetTypesOfSymbolsParams],
104+
MethodGetDiagnostics: unmarshallerFor[GetDiagnosticsParams],
105+
}
106+
107+
type ForkContextInfo struct {
108+
TypesNodeIgnorableNames []string `json:"typesNodeIgnorableNames"`
109+
NodeOnlyGlobalNames []string `json:"nodeOnlyGlobalNames"`
103110
}
104111

105112
type ConfigureParams struct {
106-
Callbacks []string `json:"callbacks"`
107-
LogFile string `json:"logFile"`
113+
Callbacks []string `json:"callbacks"`
114+
LogFile string `json:"logFile"`
115+
Fork ForkContextInfo `json:"forkContextInfo"`
108116
}
109117

110118
type ParseConfigFileParams struct {
@@ -174,6 +182,11 @@ func NewSymbolResponse(symbol *ast.Symbol) *SymbolResponse {
174182
}
175183
}
176184

185+
type GetDiagnosticsParams struct {
186+
Project Handle[project.Project] `json:"project"`
187+
FileNames []string `json:"fileNames"`
188+
}
189+
177190
type GetTypeOfSymbolParams struct {
178191
Project Handle[project.Project] `json:"project"`
179192
Symbol Handle[ast.Symbol] `json:"symbol"`

0 commit comments

Comments
 (0)