|
1 |
| -# WIP |
| 1 | +# ScrapScript LSP |
2 | 2 |
|
3 |
| ---- |
4 |
| - |
5 |
| -# ScrapScript Language Server Protocol (LSP) |
6 |
| - |
7 |
| -A Language Server Protocol implementation for the ScrapScript programming language based on tree-sitter. |
8 |
| - |
9 |
| -## Features |
10 |
| - |
11 |
| -- Syntax highlighting |
12 |
| -- Error checking and diagnostics |
13 |
| -- Code completion |
14 |
| -- Hover information |
15 |
| -- Document symbols (outline) |
16 |
| - |
17 |
| -## Installation |
18 |
| - |
19 |
| -### Prerequisites |
20 |
| - |
21 |
| -- Node.js (v16 or later) |
22 |
| -- npm |
23 |
| - |
24 |
| -### Building from Source |
25 |
| - |
26 |
| -1. Clone this repository: |
27 |
| - |
28 |
| - ```bash |
29 |
| - git clone https://github.com/scrapscript/scrapscript-lsp.git |
30 |
| - cd scrapscript-lsp |
31 |
| - ``` |
32 |
| - |
33 |
| -2. Install dependencies: |
34 |
| - |
35 |
| - ```bash |
36 |
| - npm install |
37 |
| - ``` |
38 |
| - |
39 |
| -3. Compile the language server and client: |
40 |
| - |
41 |
| - ```bash |
42 |
| - npm run compile |
43 |
| - ``` |
44 |
| - |
45 |
| -4. Build the tree-sitter WebAssembly module (needs tree-sitter CLI installed): |
46 |
| - ```bash |
47 |
| - cd server |
48 |
| - npm run build-wasm |
49 |
| - cd .. |
50 |
| - ``` |
51 |
| - |
52 |
| -### Using with VS Code |
53 |
| - |
54 |
| -1. Launch VS Code |
55 |
| -2. Open the project folder |
56 |
| -3. Press F5 to start debugging, which will launch a new VS Code window with the extension loaded |
57 |
| -4. Open a `.scrap` or `.ss` file to see the LSP in action |
58 |
| - |
59 |
| -## Development |
60 |
| - |
61 |
| -The project is structured as follows: |
62 |
| - |
63 |
| -- `client`: VS Code extension client |
64 |
| -- `server`: Language server implementation |
65 |
| -- `syntaxes`: TextMate grammar for syntax highlighting |
66 |
| -- `tree-sitter-scrapscript`: Tree-sitter grammar for the ScrapScript language |
67 |
| - |
68 |
| -### Building |
69 |
| - |
70 |
| -To build the project: |
| 3 | +## Setup |
71 | 4 |
|
| 5 | +1. Clone and install: |
72 | 6 | ```bash
|
| 7 | +git clone https://github.com/scrapscript/scrapscript-lsp.git |
| 8 | +cd scrapscript-lsp |
| 9 | +npm install |
73 | 10 | npm run compile
|
| 11 | +cd server && npm run build-wasm && cd .. |
74 | 12 | ```
|
75 | 13 |
|
76 |
| -To watch for changes: |
| 14 | +2. VS Code: |
| 15 | +- Open project folder |
| 16 | +- Press F5 to debug |
| 17 | +- Open `.scrap` or `.ss` file |
77 | 18 |
|
78 |
| -```bash |
79 |
| -npm run watch |
80 |
| -``` |
| 19 | +## Project Structure |
81 | 20 |
|
82 |
| -### Testing |
| 21 | +- `client`: VS Code extension |
| 22 | +- `server`: LSP implementation |
| 23 | +- `syntaxes`: TextMate grammar |
83 | 24 |
|
84 |
| -For testing: |
| 25 | +## Development |
85 | 26 |
|
86 | 27 | ```bash
|
87 |
| -npm test |
88 |
| -``` |
89 |
| - |
90 |
| -## Language Server Features |
91 |
| - |
92 |
| -### Syntax Highlighting |
93 |
| - |
94 |
| -The language server provides syntax highlighting through a TextMate grammar for: |
95 |
| - |
96 |
| -- Operators (`+`, `-`, `*`, `/`, etc.) |
97 |
| -- Strings, numbers, and bytes |
98 |
| -- Comments |
99 |
| -- Tags |
100 |
| -- Functions and patterns |
101 |
| - |
102 |
| -### Code Completion |
103 |
| - |
104 |
| -Code completion is provided for: |
105 |
| - |
106 |
| -- Keywords |
107 |
| -- Operators |
108 |
| -- Record fields |
109 |
| -- Tags |
110 |
| -- Common functions and values |
111 |
| - |
112 |
| -### Hover Information |
113 |
| - |
114 |
| -Hover information is provided for: |
115 |
| - |
116 |
| -- Identifiers |
117 |
| -- Operators |
118 |
| -- Tags |
119 |
| -- Functions |
120 |
| -- Built-in types and values |
121 |
| - |
122 |
| -### Document Symbols |
123 |
| - |
124 |
| -Document symbols (for the outline view) are provided for: |
125 |
| - |
126 |
| -- Declarations |
127 |
| -- Functions |
128 |
| -- Records |
129 |
| -- Lists |
130 |
| -- Tags |
131 |
| - |
132 |
| -## Contributing |
133 |
| - |
134 |
| -Contributions are welcome! Please feel free to submit a Pull Request. |
135 |
| - |
136 |
| -## License |
137 |
| - |
138 |
| -This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
139 |
| - |
140 |
| -## Acknowledgments |
141 |
| - |
142 |
| -- Taylor Troesh for the original ScrapScript language design and tree-sitter grammar |
143 |
| -- The tree-sitter team for their excellent parsing library |
144 |
| -- The Language Server Protocol community |
145 |
| - |
146 |
| ---- |
147 |
| - |
148 |
| -# Getting Started with ScrapScript LSP |
149 |
| - |
150 |
| -This guide will help you get started using and developing the ScrapScript Language Server Protocol (LSP) implementation. |
151 |
| - |
152 |
| -## Initial Setup |
153 |
| - |
154 |
| -1. Clone the repository |
155 |
| - |
156 |
| - ```bash |
157 |
| - git clone https://github.com/scrapscript/scrapscript-lsp.git |
158 |
| - cd scrapscript-lsp |
159 |
| - ``` |
160 |
| - |
161 |
| -2. Install dependencies |
162 |
| - |
163 |
| - ```bash |
164 |
| - npm install |
165 |
| - ``` |
166 |
| - |
167 |
| -3. Compile the project |
168 |
| - |
169 |
| - ```bash |
170 |
| - npm run compile |
171 |
| - ``` |
172 |
| - |
173 |
| -4. Build the tree-sitter WebAssembly module |
174 |
| - ```bash |
175 |
| - cd server |
176 |
| - npm run build-wasm |
177 |
| - cd .. |
178 |
| - ``` |
179 |
| - |
180 |
| -## Creating Your First ScrapScript File |
181 |
| - |
182 |
| -1. Create a file with the `.scrap` or `.ss` extension. |
183 |
| -2. Open it in VS Code with the ScrapScript LSP extension running. |
184 |
| -3. Start writing ScrapScript code! The language server will provide: |
185 |
| - - Syntax highlighting |
186 |
| - - Error diagnostics |
187 |
| - - Code completion |
188 |
| - - Hover information |
189 |
| - - Document symbols for navigation |
190 |
| - |
191 |
| -Example ScrapScript code: |
192 |
| - |
193 |
| -```scrapscript |
194 |
| -() |
195 |
| -
|
196 |
| -; add = x -> y -> x + y |
197 |
| -
|
198 |
| -; factorial = |
199 |
| - | 0 -> 1 |
200 |
| - | n -> n * factorial (n - 1) |
201 |
| -
|
202 |
| -; person = |
203 |
| - { name = "Alice", |
204 |
| - , age = 30 |
205 |
| - } |
206 |
| -
|
207 |
| -; evens = |
208 |
| - [1, 2, 3, 4, 5] |
209 |
| - |> list/map (x -> x * 2) |
210 |
| -``` |
211 |
| - |
212 |
| -## Repository Structure |
213 |
| - |
214 |
| -The ScrapScript LSP is organized as follows: |
215 |
| - |
216 |
| -- **Client**: The VS Code extension client that communicates with the server. |
217 |
| -- **Server**: The language server implementation providing language intelligence. |
218 |
| -- **Syntaxes**: TextMate grammar for syntax highlighting. |
219 |
| -- **Tree-sitter grammar**: The ScrapScript language grammar for parsing. |
220 |
| - |
221 |
| -## Features Overview |
222 |
| - |
223 |
| -### Syntax Highlighting |
224 |
| - |
225 |
| -The language server highlights: |
226 |
| - |
227 |
| -- Keywords |
228 |
| -- Operators |
229 |
| -- Strings and numbers |
230 |
| -- Comments |
231 |
| -- Tags |
232 |
| -- Functions and patterns |
233 |
| - |
234 |
| -### Error Checking |
235 |
| - |
236 |
| -The validator detects: |
237 |
| - |
238 |
| -- Syntax errors in expressions |
239 |
| -- Invalid declarations |
240 |
| -- Mismatched patterns |
241 |
| - |
242 |
| -### Code Completion |
243 |
| - |
244 |
| -Code completion is provided for: |
245 |
| - |
246 |
| -- Operators (`|>`, `+`, `-`, etc.) |
247 |
| -- Tags (`#true`, `#false`, etc.) |
248 |
| -- Record fields |
249 |
| - |
250 |
| -### Hover Information |
251 |
| - |
252 |
| -Hover over elements to see: |
253 |
| - |
254 |
| -- Type information |
255 |
| -- Documentation for operators and keywords |
256 |
| -- Descriptions for tags and built-in functions |
257 |
| - |
258 |
| -### Document Symbols |
259 |
| - |
260 |
| -The outline view shows: |
261 |
| - |
262 |
| -- Declarations |
263 |
| -- Functions |
264 |
| -- Records and their structure |
265 |
| -- Lists |
266 |
| - |
267 |
| -## Customizing the LSP |
268 |
| - |
269 |
| -To customize the LSP for your needs: |
270 |
| - |
271 |
| -1. **Adding More Features**: Implement additional features in the server directory by adding new provider files and connecting them in the server.ts file. |
272 |
| - |
273 |
| -2. **Extending the Grammar**: If you need to modify the grammar, update the tree-sitter grammar file and rebuild the WASM module. |
274 |
| - |
275 |
| -3. **Improving Completions**: Enhance the completions.ts file to provide more context-aware suggestions. |
276 |
| - |
277 |
| -4. **Adding Semantic Analysis**: Implement more sophisticated validations in validator.ts. |
278 |
| - |
279 |
| -## Debugging |
280 |
| - |
281 |
| -To debug the LSP: |
282 |
| - |
283 |
| -1. Open the project in VS Code |
284 |
| -2. Press F5 to start debugging |
285 |
| -3. A new VS Code window will open with the extension loaded |
286 |
| -4. Open a ScrapScript file to test the LSP |
287 |
| - |
288 |
| -You can set breakpoints in both the client and server code to debug specific issues. |
289 |
| - |
290 |
| -## Contributing |
291 |
| - |
292 |
| -Contributions to the ScrapScript LSP are welcome! Ways to contribute: |
293 |
| - |
294 |
| -1. **Report Issues**: File issues for bugs or feature requests. |
295 |
| -2. **Improve Documentation**: Help clarify or expand the documentation. |
296 |
| -3. **Add Features**: Implement new features or improve existing ones. |
297 |
| -4. **Fix Bugs**: Address open issues or bugs you encounter. |
298 |
| - |
299 |
| -Happy coding with ScrapScript! |
300 |
| - |
| 28 | +npm run compile # Build |
| 29 | +npm run watch # Watch mode |
| 30 | +npm test # Run tests |
| 31 | +``` |
0 commit comments