ucode-lsp 0.6.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Noah Peterson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,187 @@
1
+ # ucode Language Server Protocol (LSP)
2
+
3
+ A comprehensive Language Server Protocol implementation for the [ucode scripting language](https://github.com/jow-/ucode), providing autocompletion of known module functions and builtins, syntax highlighting, function definition go-to, basic type inference, and syntax error diagnostics.
4
+
5
+ ## Features
6
+
7
+ ### Autocompletion
8
+ - Context-aware completions for builtin functions, variables, and module members
9
+ - Module-specific completions (e.g., `fs.open()`, `fs.readfile()`)
10
+ - Variable name suggestions from current scope including imported modules
11
+ - Function signature hints and parameter information
12
+
13
+ ### Error Detection & Diagnostics
14
+ - Precise error reporting with line/column positions. No more vague "left-hand side is not a function" errors.
15
+ - Context-aware diagnostics
16
+ - Basic Type Inference with union types (`integer | string | null`), so you are aware of what data types you are working with before deploying your code.
17
+ - Function call validation against known signatures with proper argument count checking
18
+ - Scope analysis detecting undefined variables and shadowing
19
+
20
+ ### Code Navigation
21
+ - Go to Definition for imported functions across files
22
+ - Symbol resolution with cross-file analysis
23
+ - Hover information showing types and function signatures
24
+
25
+ ### Performance Optimized
26
+ - Caching system for analysis results
27
+
28
+ ## Quick Start
29
+
30
+ ### npm (CLI + LSP server)
31
+ ```bash
32
+ npm install -g ucode-lsp
33
+ ```
34
+
35
+ This gives you the `ucode-lsp` command with two modes:
36
+
37
+ **Check mode** — scan files and print diagnostics (like `tsc`):
38
+ ```bash
39
+ ucode-lsp # check all .uc files in current directory
40
+ ucode-lsp src/ # check a specific directory
41
+ ucode-lsp file.uc # check a specific file
42
+ ucode-lsp --verbose # include info-level diagnostics
43
+ ```
44
+
45
+ **LSP server mode** — for editors:
46
+ ```bash
47
+ ucode-lsp --stdio # start LSP server over stdio
48
+ ```
49
+
50
+ Run `ucode-lsp --help` for all options, or `ucode-lsp --help-types` for the type annotation guide. A man page is also available: `man ucode-lsp`.
51
+
52
+ ### VS Code
53
+ Install the extension from the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=noahbpeterson.ucode-lsp).
54
+
55
+ ### Neovim (0.11+)
56
+ Add to `~/.config/nvim/init.lua`:
57
+ ```lua
58
+ vim.filetype.add({ extension = { uc = 'ucode' } })
59
+
60
+ vim.lsp.config('ucode', {
61
+ cmd = { 'ucode-lsp', '--stdio' },
62
+ filetypes = { 'ucode' },
63
+ root_markers = { '.git' },
64
+ })
65
+ vim.lsp.enable('ucode')
66
+ ```
67
+
68
+ ### Building from Source
69
+ ```bash
70
+ git clone https://github.com/NoahBPeterson/ucode-lsp.git
71
+ cd ucode-lsp
72
+ bun install && bun run compile
73
+ npm install -g . # install CLI globally from local build
74
+ ```
75
+
76
+ This produces:
77
+ - `dist/server.js` — LSP server
78
+ - `dist/cli.js` — CLI checker
79
+ - `bin/ucode-lsp.js` — entry point (routes to server or CLI)
80
+
81
+ ## Language Support
82
+
83
+ ### Syntax Highlighting
84
+ - Complete ucode language grammar
85
+ - Proper tokenization for all language constructs
86
+ - Context-aware highlighting for keywords, operators, and literals
87
+
88
+ ### Error Detection
89
+ ```ucode
90
+ split("hello", 123); // Error: expects (string, string)
91
+ length(42); // Error: expects string, got number
92
+
93
+ let x = 5;
94
+ function test() {
95
+ print(y); // Error: 'y' is not defined
96
+ let x = 10; // Warning: shadows outer 'x'
97
+ let e = open(); // Error: Undefined function: open
98
+ };
99
+
100
+ function myFunc() { // Error: Functions must end with a semicolon ';'
101
+ return 42;
102
+ }
103
+ ```
104
+
105
+ ### Module Support & Autocompletion
106
+ Complete IntelliSense for built-in modules:
107
+ ```ucode
108
+ import { create, connect, AF_INET, SOCK_STREAM } from 'socket';
109
+ import * as math from 'math';
110
+ import { query } from 'resolv';
111
+ const fs = require('fs');
112
+
113
+ let sock = create(AF_INET, SOCK_STREAM); // ✅ Full autocomplete
114
+ let result = connect(sock, "example.com", "80");
115
+ let sqrt_val = math.sqrt(16); // ✅ Namespace imports
116
+
117
+ // Smart module-specific completions
118
+ let file = fs.open("test.txt", "r"); // ✅ fs.open(), fs.readfile(), fs.writefile()...
119
+ let content = fs.readfile("data.txt"); // ✅ All 27 fs module functions available
120
+ ```
121
+
122
+ **Supported Modules:**
123
+ - **socket** - Network socket functionality (create, connect, listen, etc.)
124
+ - **math** - Mathematical functions (sin, cos, sqrt, etc.)
125
+ - **log** - System logging (syslog, ulog functions)
126
+ - **resolv** - DNS resolution (query, error functions)
127
+ - **nl80211** - WiFi/802.11 networking
128
+ - **debug** - Runtime debugging and introspection
129
+ - **digest** - Cryptographic hash functions
130
+ - **fs** - File system operations with comprehensive autocompletion for all 27 functions (open, readfile, writefile, stat, access, etc.)
131
+ - **uci** - OpenWrt UCI configuration management
132
+ - **uloop** - Event loop and timer functionality
133
+
134
+ ### Code Navigation
135
+ ```ucode
136
+ import { run_command } from '../lib/commands.uc';
137
+
138
+ function process() {
139
+ run_command("netstat"); // Right-click → Go to Definition
140
+ }
141
+ ```
142
+
143
+ ## Architecture
144
+
145
+ ### Core Components
146
+ - Lexer (`src/lexer/`) - Tokenization and basic syntax validation
147
+ - Parser (`src/parser/`) - AST generation with error recovery
148
+ - Semantic Analyzer (`src/analysis/`) - Type checking and scope analysis
149
+ - LSP Server (`src/server.ts`) - Editor integration via LSP (editor-agnostic)
150
+ - CLI Checker (`src/cli.ts`) - Standalone diagnostic output (like `tsc`)
151
+
152
+ ## Configuration
153
+
154
+ ### VS Code Settings
155
+ ```json
156
+ {
157
+ "ucode.maxNumberOfProblems": 100,
158
+ "ucode.trace.server": "verbose"
159
+ }
160
+ ```
161
+
162
+ ### Validation Modes
163
+ - `lexer` - Basic token-based validation
164
+ - `ast-basic` - AST parser with fallback (recommended)
165
+ - `ast-full` - Full semantic analysis
166
+
167
+ ## Contributing
168
+
169
+ ### Development Workflow
170
+ 1. Make changes to source files in `src/`
171
+ 2. Follow the steps in Development Setup
172
+ 3. Test with VS Code extension host
173
+ 4. Submit pull request
174
+
175
+ ### Testing
176
+ ```bash
177
+ # Primary testing with Bun
178
+ bun test
179
+
180
+ # For Bun compatibility issues, use Node.js fallback:
181
+ npx mocha tests/test-real-double-diagnostic-fix.test.js
182
+ node tests/specific-test-file.js
183
+ ```
184
+
185
+ ## License
186
+
187
+ MIT License - see [LICENSE](LICENSE) file for details.
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ if (process.argv.includes('--stdio') ||
3
+ process.argv.includes('--pipe') ||
4
+ process.argv.includes('--node-ipc') ||
5
+ process.argv.some(a => a.startsWith('--socket='))) {
6
+ require('../dist/server.js');
7
+ } else {
8
+ require('../dist/cli.js');
9
+ }