Skip to content

Commit 4287004

Browse files
authored
Changes for deno CLI (#1)
* Make resolver swappable * refactor out session / project host * init wrapper host * actually use custom host * more wiring for api * resolver callbacks * deno lib files + some fixes * return both line/char and byte pos * implied node format on resolver * add isNodeSourceFile hook * wip * massive symbol table refactor * ughhh * debugging * callback for isNodesourceFile * merge symbol fix * fixes * cleanup * merge fixup * release workflow * fix workflow * fix workflow * pass source line in diagnostic * upload source to release * always treat case sensitive * do not include lib files * put binary at root of release zip * asset libpath
1 parent cc551fb commit 4287004

Some content is hidden

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

51 files changed

+1737
-407
lines changed

.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) {

cmd/tsgo/main.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package main
22

33
import (
44
"os"
5-
6-
"github.com/microsoft/typescript-go/internal/execute"
75
)
86

97
func main() {
@@ -14,12 +12,9 @@ func runMain() int {
1412
args := os.Args[1:]
1513
if len(args) > 0 {
1614
switch args[0] {
17-
case "--lsp":
18-
return runLSP(args[1:])
1915
case "--api":
2016
return runAPI(args[1:])
2117
}
2218
}
23-
result := execute.CommandLine(newSystem(), args, nil)
24-
return int(result.Status)
19+
return 1
2520
}

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)))
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]) ([]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, snapshot.Converters())
281+
diagnostics := languageService.GetDiagnostics(ctx)
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: 6 additions & 0 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,6 +101,7 @@ var unmarshalers = map[Method]func([]byte) (any, error){
100101
MethodGetSymbolsAtLocations: unmarshallerFor[GetSymbolsAtLocationsParams],
101102
MethodGetTypeOfSymbol: unmarshallerFor[GetTypeOfSymbolParams],
102103
MethodGetTypesOfSymbols: unmarshallerFor[GetTypesOfSymbolsParams],
104+
MethodGetDiagnostics: unmarshallerFor[GetDiagnosticsParams],
103105
}
104106

105107
type ConfigureParams struct {
@@ -174,6 +176,10 @@ func NewSymbolResponse(symbol *ast.Symbol) *SymbolResponse {
174176
}
175177
}
176178

179+
type GetDiagnosticsParams struct {
180+
Project Handle[project.Project] `json:"project"`
181+
}
182+
177183
type GetTypeOfSymbolParams struct {
178184
Project Handle[project.Project] `json:"project"`
179185
Symbol Handle[ast.Symbol] `json:"symbol"`

0 commit comments

Comments
 (0)