You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-6Lines changed: 18 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,34 @@
1
-
2
1
# TypeScript Server (TSserver) Documentation Project
3
2
4
-
TSserver is a powerful tool that enhances TypeScript coding and project management. However, we recognize that the lack of human-readable documentation can be a barrier to effectively utilizing its full potential. To address this challenge, our project focuses on generating simple, accessible JSDoc documentation. Our goal is to make TSserver more user-friendly, allowing anyone to leverage its capabilities without the need to decipher complex TypeScript code syntaxes.
3
+
TSserver is a powerful tool that enhances TypeScript coding and project management. However, we recognize that the lack
4
+
of human-readable documentation can be a barrier to effectively utilizing its full potential. To address this challenge,
5
+
our project focuses on generating simple, accessible JSDoc documentation. Our goal is to make TSserver more
6
+
user-friendly, allowing anyone to leverage its capabilities without the need to decipher complex TypeScript code
7
+
syntaxes.
5
8
6
9
## Project Objective
7
10
8
-
Our main objective is to transform the complex and cryptic syntaxes of TSserver into easy-to-understand documentation. We aim to provide clear, concise, and practical guides that cater to both beginners and experienced TypeScript developers.
11
+
Our main objective is to transform the complex and cryptic syntaxes of TSserver into easy-to-understand documentation.
12
+
We aim to provide clear, concise, and practical guides that cater to both beginners and experienced TypeScript
13
+
developers.
14
+
15
+
## Phoenix code LSP experiments
16
+
17
+
Please see `src/experiments/readme.md` for experiments and results for future LSP integration
18
+
into Phoenix Code.
9
19
10
20
## Getting Started
11
21
12
22
To get started with TSserver using our JSDoc documentation:
13
23
14
-
- Open the `utils/server.js` file in your project.
15
-
- View the JSDoc comments above each function to understand their usage and capabilities.
24
+
-Open the `utils/server.js` file in your project.
25
+
-View the JSDoc comments above each function to understand their usage and capabilities.
16
26
17
27
## Contributing
18
28
19
-
We welcome contributions to improve and expand the documentation. If you have insights, examples, or enhancements, please feel free to contribute. Check out our [Contributing Guide](CONTRIBUTING.md) for guidelines on how to make submissions.
29
+
We welcome contributions to improve and expand the documentation. If you have insights, examples, or enhancements,
30
+
please feel free to contribute. Check out our [Contributing Guide](CONTRIBUTING.md) for guidelines on how to make
A Node.js CLI tool for getting TypeScript/JavaScript code completions using the Language Server Protocol (LSP), inspired by Zed editor's implementation.
3
+
## Overview
4
+
5
+
This experiments folder explores TypeScript/JavaScript code completions and language features using the Language Server Protocol
6
+
(LSP).
7
+
8
+
## Experiments
9
+
10
+
### TypeScript Language Server
11
+
12
+
We have a working implementation in the `experiments` folder that uses the Language Server Protocol with
13
+
[typescript-language-server](https://github.com/typescript-language-server/typescript-language-server). This approach,
14
+
inspired by Zed editor's implementation, proved to be more straightforward and effective than alternatives.
15
+
16
+
The experiment demonstrates:
17
+
18
+
- Functional code completions for JavaScript and TypeScript files
19
+
- Property access completion with proper context
20
+
- Integration with project-specific TypeScript installations
21
+
- Robust message handling for LSP communication
22
+
23
+
See the [experiments README](./experiments/README.md) for implementation details and lessons learned.
24
+
25
+
### Alternative Approaches
26
+
27
+
We also investigated using the TypeScript server directly, based on VS Code's TypeScript implementation. However, this
28
+
approach proved unnecessarily complex compared to the LSP-based solution. The typescript-language-server abstraction
29
+
provided a cleaner interface while maintaining all the functionality we needed.
30
+
31
+
## Key Challenges Solved
32
+
33
+
One of the main problems we encountered was getting relevant code hints. The language service initially returned either:
34
+
35
+
1. Too many irrelevant completions without proper context
36
+
2. No completions at all in certain scenarios (particularly with property access)
37
+
38
+
The critical fix was properly specifying trigger characters and trigger kinds in completion requests. See the
39
+
documentation below for details on this and other challenges we overcame.
40
+
41
+
## Phoenix Code Integration Recommendations
42
+
43
+
Based on our findings, here are the recommendations for integrating with Phoenix Code:
44
+
45
+
1. The existing Brackets LSP code in Phoenix Code already handles most cases for:
46
+
47
+
- Code completions
48
+
- Jump to definition/declarations
49
+
- Hover information
50
+
- Other language features
51
+
52
+
2. For integration, the main work needed is:
53
+
- Implement Node.js connectors in Phoenix Code
54
+
- Configure communication with the TypeScript language server
55
+
- Ensure proper trigger character handling for completions
56
+
57
+
The existing LSP infrastructure in Phoenix Code provides a solid foundation, and with proper connections to the
58
+
TypeScript language server, you should be able to achieve full functionality without significant architectural changes.
59
+
60
+
# Getting Started
61
+
62
+
See the docs below for setup instructions and example usage of the prototype implementation.
63
+
64
+
## TypeScript Language Server Client
65
+
66
+
A Node.js CLI tool for getting TypeScript/JavaScript code completions using the Language Server Protocol (LSP), inspired
**Challenge**: Code completions for imported modules weren't working initially.
87
155
88
-
**Solution**: While we implemented a `syncRelatedFiles` function to provide context to the language server, we discovered that this wasn't actually the main issue. The key fix was properly specifying the trigger character (see below).
156
+
**Solution**: While we implemented a `syncRelatedFiles` function to provide context to the language server, we
157
+
discovered that this wasn't actually the main issue. The key fix was properly specifying the trigger character (see
158
+
below).
89
159
90
-
**Note**: The file syncing code is currently prepared but may not be necessary in most cases as long as the trigger character is correctly specified:
160
+
**Note**: The file syncing code is currently prepared but may not be necessary in most cases as long as the trigger
161
+
character is correctly specified:
91
162
92
163
```javascript
93
164
// Find and open all related files in the directory
### 5. Completion Parameters and Trigger Characters
100
171
101
-
**Challenge**: Property completions for object members weren't showing up at all. For example, with code like `config.se<cursor>rver.port`, no completions were being returned, even though VS Code would show property suggestions.
172
+
**Challenge**: Property completions for object members weren't showing up at all. For example, with code like
173
+
`config.se<cursor>rver.port`, no completions were being returned, even though VS Code would show property suggestions.
102
174
103
175
**Solution**: Adding the correct trigger character (".") to completion requests was critical:
104
176
@@ -121,27 +193,28 @@ async function syncRelatedFiles(server, projectRoot, targetFile) {
121
193
```
122
194
123
195
**Important**: The trigger character should match the character that triggered the completion:
124
-
- For property access (`config.se<cursor>rver`), the trigger character should be "."
125
-
- For regular identifier completions (`con<cursor>fig`), you should omit the trigger character
126
-
- Using the wrong trigger character can result in irrelevant completions or no completions at all
127
196
128
-
This was the single most important fix that made property completions work correctly.
197
+
- For property access (`config.se<cursor>rver`), the trigger character should be "."
198
+
- For regular identifier completions (`con<cursor>fig`), you should omit the trigger character
199
+
- Using the wrong trigger character can result in irrelevant completions or no completions at all
129
200
201
+
This was the single most important fix that made property completions work correctly.
130
202
131
203
### 6. TypeScript Detection
132
204
133
205
**Challenge**: Needed to detect and use the local project's TypeScript installation.
134
206
135
207
**Solution**: Checked common installation paths and provided fallbacks:
**Important**: Do not include a trigger character for regular identifier completions - it will filter results incorrectly. Only include the trigger character that was actually typed by the user to trigger the completion.
246
+
**Important**: Do not include a trigger character for regular identifier completions - it will filter results
247
+
incorrectly. Only include the trigger character that was actually typed by the user to trigger the completion.
173
248
174
249
## Next Steps
175
250
176
251
Potential improvements:
252
+
177
253
1. Add support for document changes (editing files)
178
254
2. Implement completion item resolution for more details
179
255
3. Add signature help support
@@ -184,6 +260,6 @@ Potential improvements:
184
260
185
261
## References
186
262
187
-
-[Language Server Protocol Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/)
188
-
-[TypeScript Language Server](https://github.com/typescript-language-server/typescript-language-server)
0 commit comments