Skip to content

Commit f1125de

Browse files
committed
Integrate Ruff support for Python code formatting in Pyright LSP Bridge
- Added a new build script `build-with-ruff.sh` to facilitate building with Ruff support for Linux and macOS. - Updated `build.sh` to download and include the Ruff binary for Linux builds. - Enhanced `pyright-bridge.ts` to intercept formatting requests and handle them using Ruff. - Introduced `formatting.ts` to manage the formatting logic with Ruff. - Updated documentation in `AGENTS.md` to reflect the new Ruff integration and build instructions. - Modified `.gitignore` to include Ruff-related files and binaries.
1 parent b1e150f commit f1125de

File tree

9 files changed

+818
-25
lines changed

9 files changed

+818
-25
lines changed

.github/workflows/build-and-release.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
name: Build and Release
1+
name: Build and Release (Legacy - No Ruff)
22

33
on:
4-
push:
5-
tags: ['v*']
4+
# Disabled automatic tag builds - use build-with-ruff.yml instead
5+
# push:
6+
# tags: ['v*']
67
workflow_dispatch:
78

89
permissions:
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
name: Build with Ruff Support
2+
3+
on:
4+
push:
5+
tags: ['v*']
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
env:
12+
NODE_VERSION: 'v20.11.0'
13+
RUFF_VERSION: '0.14.3'
14+
15+
jobs:
16+
linux:
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
arch: [x64]
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- uses: actions/setup-node@v4
25+
with:
26+
node-version: '20'
27+
28+
- name: Install dependencies
29+
run: npm install
30+
31+
- name: Build for linux-${{ matrix.arch }} with Ruff
32+
run: |
33+
PLATFORM="linux-${{ matrix.arch }}"
34+
NODE_ARCH="linux-${{ matrix.arch }}"
35+
36+
mkdir -p output/${PLATFORM}
37+
38+
# Bundle TypeScript with esbuild
39+
npx esbuild index.ts \
40+
--bundle \
41+
--platform=node \
42+
--target=node18 \
43+
--format=esm \
44+
--outfile=output/${PLATFORM}/bundle.js \
45+
--external:ws \
46+
--external:vscode-ws-jsonrpc \
47+
--external:vscode-jsonrpc \
48+
--external:dotenv
49+
50+
# Download Node.js runtime
51+
NODE_PKG="node-${NODE_VERSION}-${NODE_ARCH}"
52+
NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_PKG}.tar.gz"
53+
curl -L "${NODE_URL}" -o /tmp/${NODE_PKG}.tar.gz
54+
tar -xzf /tmp/${NODE_PKG}.tar.gz -C /tmp/
55+
mv /tmp/${NODE_PKG} output/${PLATFORM}/node
56+
57+
# Strip unnecessary files from Node.js
58+
cd output/${PLATFORM}/node
59+
rm -rf lib/node_modules/npm lib/node_modules/corepack
60+
rm -f bin/npm bin/npx bin/corepack
61+
rm -rf share/doc share/man share/systemtap include
62+
rm -f README.md CHANGELOG.md LICENSE *.md
63+
strip bin/node 2>/dev/null || true
64+
cd ../../..
65+
66+
# Download Ruff for Linux
67+
echo "Downloading Ruff ${RUFF_VERSION} for linux-x64..."
68+
RUFF_URL="https://github.com/astral-sh/ruff/releases/download/${RUFF_VERSION}/ruff-x86_64-unknown-linux-gnu.tar.gz"
69+
mkdir -p output/${PLATFORM}/bin
70+
curl -L -A "Mozilla/5.0" "${RUFF_URL}" -o /tmp/ruff.tar.gz
71+
tar -xzf /tmp/ruff.tar.gz -C /tmp/
72+
cp /tmp/ruff-x86_64-unknown-linux-gnu/ruff output/${PLATFORM}/bin/ruff
73+
chmod +x output/${PLATFORM}/bin/ruff
74+
75+
# Install production dependencies
76+
cp package.json output/${PLATFORM}/
77+
cd output/${PLATFORM}
78+
npm install --production --no-optional
79+
rm package-lock.json
80+
echo '{"type":"module"}' > package.json
81+
82+
# Prune unnecessary files from node_modules
83+
find node_modules -type d -name "test" -exec rm -rf {} + 2>/dev/null || true
84+
find node_modules -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true
85+
find node_modules -type d -name "docs" -exec rm -rf {} + 2>/dev/null || true
86+
find node_modules -type f -name "*.md" -delete 2>/dev/null || true
87+
find node_modules -type f -name "*.ts" ! -name "*.d.ts" -delete 2>/dev/null || true
88+
find node_modules -type f -name "*.map" -delete 2>/dev/null || true
89+
cd ../..
90+
91+
# Copy config template
92+
cp pyrightconfig.json output/${PLATFORM}/
93+
94+
# Create start script with RUFF_PATH
95+
cat > output/${PLATFORM}/start.sh << 'EOF'
96+
#!/bin/bash
97+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
98+
export RUFF_PATH="${DIR}/bin/ruff"
99+
"${DIR}/node/bin/node" "${DIR}/bundle.js" "$@"
100+
EOF
101+
chmod +x output/${PLATFORM}/start.sh
102+
103+
# Create compressed archive
104+
cd output
105+
tar -czf ${PLATFORM}.tar.gz ${PLATFORM}/
106+
cd ..
107+
108+
- name: Upload artifact
109+
uses: actions/upload-artifact@v4
110+
with:
111+
name: linux-${{ matrix.arch }}
112+
path: output/linux-${{ matrix.arch }}.tar.gz
113+
114+
macos:
115+
runs-on: macos-latest
116+
strategy:
117+
matrix:
118+
arch: [x64, arm64]
119+
steps:
120+
- uses: actions/checkout@v4
121+
122+
- uses: actions/setup-node@v4
123+
with:
124+
node-version: '20'
125+
126+
- name: Install dependencies
127+
run: npm install
128+
129+
- name: Build for darwin-${{ matrix.arch }} with Ruff
130+
run: |
131+
PLATFORM="darwin-${{ matrix.arch }}"
132+
NODE_ARCH="darwin-${{ matrix.arch }}"
133+
134+
mkdir -p output/${PLATFORM}
135+
136+
# Bundle TypeScript with esbuild
137+
npx esbuild index.ts \
138+
--bundle \
139+
--platform=node \
140+
--target=node18 \
141+
--format=esm \
142+
--outfile=output/${PLATFORM}/bundle.js \
143+
--external:ws \
144+
--external:vscode-ws-jsonrpc \
145+
--external:vscode-jsonrpc \
146+
--external:dotenv
147+
148+
# Download Node.js runtime
149+
NODE_PKG="node-${NODE_VERSION}-${NODE_ARCH}"
150+
NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_PKG}.tar.gz"
151+
curl -L "${NODE_URL}" -o /tmp/${NODE_PKG}.tar.gz
152+
tar -xzf /tmp/${NODE_PKG}.tar.gz -C /tmp/
153+
mv /tmp/${NODE_PKG} output/${PLATFORM}/node
154+
155+
# Strip unnecessary files from Node.js (no strip on macOS binaries)
156+
cd output/${PLATFORM}/node
157+
rm -rf lib/node_modules/npm lib/node_modules/corepack
158+
rm -f bin/npm bin/npx bin/corepack
159+
rm -rf share/doc share/man share/systemtap include
160+
rm -f README.md CHANGELOG.md LICENSE *.md
161+
cd ../../..
162+
163+
# Download Ruff for macOS
164+
echo "Downloading Ruff ${RUFF_VERSION} for darwin-${{ matrix.arch }}..."
165+
if [ "${{ matrix.arch }}" = "x64" ]; then
166+
RUFF_ARCH="x86_64"
167+
else
168+
RUFF_ARCH="aarch64"
169+
fi
170+
RUFF_URL="https://github.com/astral-sh/ruff/releases/download/${RUFF_VERSION}/ruff-${RUFF_ARCH}-apple-darwin.tar.gz"
171+
mkdir -p output/${PLATFORM}/bin
172+
curl -L -A "Mozilla/5.0" "${RUFF_URL}" -o /tmp/ruff.tar.gz
173+
tar -xzf /tmp/ruff.tar.gz -C /tmp/
174+
cp /tmp/ruff-${RUFF_ARCH}-apple-darwin/ruff output/${PLATFORM}/bin/ruff
175+
chmod +x output/${PLATFORM}/bin/ruff
176+
177+
# Install production dependencies
178+
cp package.json output/${PLATFORM}/
179+
cd output/${PLATFORM}
180+
npm install --production --no-optional
181+
rm package-lock.json
182+
echo '{"type":"module"}' > package.json
183+
184+
# Prune unnecessary files from node_modules
185+
find node_modules -type d -name "test" -exec rm -rf {} + 2>/dev/null || true
186+
find node_modules -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true
187+
find node_modules -type d -name "docs" -exec rm -rf {} + 2>/dev/null || true
188+
find node_modules -type f -name "*.md" -delete 2>/dev/null || true
189+
find node_modules -type f -name "*.ts" ! -name "*.d.ts" -delete 2>/dev/null || true
190+
find node_modules -type f -name "*.map" -delete 2>/dev/null || true
191+
cd ../..
192+
193+
# Copy config template
194+
cp pyrightconfig.json output/${PLATFORM}/
195+
196+
# Create start script with RUFF_PATH
197+
cat > output/${PLATFORM}/start.sh << 'EOF'
198+
#!/bin/bash
199+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
200+
export RUFF_PATH="${DIR}/bin/ruff"
201+
"${DIR}/node/bin/node" "${DIR}/bundle.js" "$@"
202+
EOF
203+
chmod +x output/${PLATFORM}/start.sh
204+
205+
# Create compressed archive
206+
cd output
207+
tar -czf ${PLATFORM}.tar.gz ${PLATFORM}/
208+
cd ..
209+
210+
- name: Upload artifact
211+
uses: actions/upload-artifact@v4
212+
with:
213+
name: darwin-${{ matrix.arch }}
214+
path: output/darwin-${{ matrix.arch }}.tar.gz
215+
216+
release:
217+
name: Create GitHub Release
218+
runs-on: ubuntu-latest
219+
needs: [linux, macos]
220+
if: startsWith(github.ref, 'refs/tags/v')
221+
222+
steps:
223+
- name: Download all artifacts
224+
uses: actions/download-artifact@v4
225+
with:
226+
path: artifacts
227+
merge-multiple: true
228+
229+
- name: Create Release
230+
uses: softprops/action-gh-release@v1
231+
with:
232+
files: artifacts/*
233+
draft: false
234+
prerelease: false
235+
generate_release_notes: true
236+
body: |
237+
## Pyright LSP Bridge with Ruff Formatting Support
238+
239+
This release includes Ruff formatter bundled with the language server.
240+
241+
### Platform Support
242+
- ✅ Linux x64 with Ruff
243+
- ✅ macOS Intel (x64) with Ruff
244+
- ✅ macOS Apple Silicon (arm64) with Ruff
245+
246+
### Features
247+
- Python language server (Pyright)
248+
- Code formatting (Ruff)
249+
- Cross-platform support
250+
- Bundled Node.js runtime
251+
252+
### Installation
253+
254+
**Linux:**
255+
```bash
256+
tar -xzf linux-x64-with-ruff.tar.gz
257+
cd linux-x64
258+
./start.sh --port 9011 --bot-root /path/to/bot --jesse-root /path/to/jesse
259+
```
260+
261+
**macOS:**
262+
```bash
263+
tar -xzf darwin-arm64-with-ruff.tar.gz # or darwin-x64-with-ruff.tar.gz
264+
cd darwin-arm64 # or darwin-x64
265+
./start.sh --port 9011 --bot-root /path/to/bot --jesse-root /path/to/jesse
266+
```
267+
env:
268+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
269+

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,5 @@ vite.config.ts.timestamp-*
142142
build/
143143
output/
144144
*.tar.gz
145-
*.zip
145+
*.zip
146+
bin/

AGENTS.md

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The python-language-server (pyright-lsp) repository is a WebSocket bridge for th
1414
- **TypeScript** - Main language for the bridge implementation
1515
- **Node.js** - Runtime environment
1616
- **Pyright** - Microsoft's static type checker for Python
17+
- **Ruff** - Fast Python linter and formatter (bundled for formatting support)
1718
- **WebSocket (ws)** - WebSocket communication
1819
- **vscode-ws-jsonrpc** - JSON-RPC over WebSocket
1920
- **esbuild** - Fast JavaScript bundler
@@ -35,32 +36,53 @@ npm start -- --port 9011 --project-root /path/to/project --jesse-relative-path j
3536

3637
### Building for Production
3738

38-
#### Single Platform (Linux x64)
39+
#### Quick Builds with Ruff Support
3940
```bash
40-
./build.sh
41+
# Build for Linux x64 with Ruff formatting support
42+
npm run build:linux
43+
44+
# Build for macOS (Intel and Apple Silicon) with Ruff
45+
npm run build:mac
46+
47+
# Build for Linux and macOS with Ruff
48+
npm run build:all
49+
50+
# Or use the script directly for specific platforms
51+
./build-with-ruff.sh linux:x64 darwin:arm64
4152
```
42-
Output: `output/linux-x64.tar.gz` (~34 MB)
4353

44-
#### All Platforms
54+
#### Legacy Builds (without Ruff)
4555
```bash
56+
# Linux x64 only (Pyright only, no Ruff)
57+
./build.sh
58+
59+
# All platforms (Pyright only, no Ruff)
4660
./build-all.sh
4761
```
48-
Outputs:
49-
- `linux-x64.tar.gz` / `linux-arm64.tar.gz`
50-
- `darwin-x64.tar.gz` / `darwin-arm64.tar.gz`
51-
- `win32-x64.zip`
5262

5363
### Build Scripts
54-
- `build.sh` - Build for Linux x64 only
55-
- `build-all.sh` - Build for all supported platforms
64+
- `build.sh` - Build for Linux x64 only (no Ruff)
65+
- `build-all.sh` - Build for all supported platforms (no Ruff)
66+
- `build-with-ruff.sh` - Build with Ruff formatting support for Linux & macOS
67+
68+
### Build Outputs
69+
**With Ruff (recommended):**
70+
- `linux-x64.tar.gz` (~46 MB) - Includes Ruff formatter
71+
- `darwin-x64.tar.gz` (~44 MB) - Intel Mac with Ruff
72+
- `darwin-arm64.tar.gz` (~44 MB) - Apple Silicon with Ruff
73+
74+
**Without Ruff:**
75+
- `linux-x64.tar.gz` (~34 MB) - Pyright only
5676

5777
## Important Notes
5878

5979
### Architecture
6080
- **WebSocket Bridge** - Translates WebSocket messages to Pyright LSP protocol
61-
- **Bundled Runtime** - Includes Node.js, eliminating system dependencies
81+
- **Formatting Interception** - Intercepts LSP formatting requests and handles them with Ruff
82+
- **Bundled Runtime** - Includes Node.js (and Ruff if built with `build-with-ruff.sh`)
83+
- **Strategy Module Support** - Automatically handles Jesse's strategy structure (`.py` files that are actually `__init__.py` modules)
6284
- **Production-only Dependencies** - Optimized builds exclude dev dependencies
63-
- **70% Size Reduction** - Optimized build process significantly reduces package size
85+
- **Cross-Platform** - All path handling uses Node.js `path` module for Windows/Linux/macOS compatibility
6486

6587
### Code Style
6688
- Don't write comments for functions unless specifically asked

0 commit comments

Comments
 (0)