@wire-dsl/language-support 0.0.2

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.
@@ -0,0 +1,218 @@
1
+ # Reutilizando Wire DSL Language Support Across Tools
2
+
3
+ ## Resumen
4
+
5
+ Hemos creado el package `@wire-dsl/language-support` como una fuente centralizada de definiciones de lenguaje. Esto permite que VS Code Extension, Monaco Editor, y otros editores usen las mismas definiciones sin duplicación.
6
+
7
+ ## Estructura
8
+
9
+ ```
10
+ packages/
11
+ ├── language-support/ ← Nueva fuente centralizada
12
+ │ ├── src/
13
+ │ │ ├── index.ts # Keywords, componentes, propiedades
14
+ │ │ ├── grammar.ts # Configuración de tokens para Monaco
15
+ │ │ └── completions.ts # Lógica de autocompletado
16
+ │ ├── dist/ # JavaScript compilado
17
+ │ └── package.json
18
+
19
+ ├── web/ # Wire Live Editor
20
+ │ ├── src/
21
+ │ │ └── monaco/
22
+ │ │ └── wireLanguage.ts # Usa @wire-dsl/language-support
23
+ │ └── package.json # Dependencia: @wire-dsl/language-support
24
+
25
+ └── vscode-extension/ # (Futuro) Usar language-support también
26
+ └── src/
27
+ ├── completionProvider.ts
28
+ └── data/
29
+ └── components.ts
30
+ ```
31
+
32
+ ## Cómo Usar en Monaco (Web)
33
+
34
+ ```typescript
35
+ // packages/web/src/monaco/wireLanguage.ts
36
+ import { ALL_KEYWORDS, getCompletions } from '@wire-dsl/language-support';
37
+
38
+ export function registerWireLanguage() {
39
+ // Usar keywords dinámicamente
40
+ const keywordPattern = ALL_KEYWORDS.map(kw => kw.name).join('|');
41
+
42
+ // Tokenizer usa el patrón
43
+ monaco.languages.setMonarchTokensProvider('wire', {
44
+ tokenizer: {
45
+ root: [
46
+ [new RegExp(`\\b(${keywordPattern})\\b`), 'keyword'],
47
+ // ...
48
+ ],
49
+ },
50
+ });
51
+
52
+ // Autocompletado usa language-support
53
+ monaco.languages.registerCompletionItemProvider('wire', {
54
+ provideCompletionItems: (model, position) => {
55
+ const word = getWord(model, position);
56
+ return {
57
+ suggestions: getCompletions(word).map(item => ({
58
+ label: item.label,
59
+ kind: getKind(item.kind),
60
+ detail: item.documentation,
61
+ })),
62
+ };
63
+ },
64
+ });
65
+ }
66
+ ```
67
+
68
+ ## Cómo Usar en VS Code Extension
69
+
70
+ ### Opción 1: Reutilizar directamente (Recomendado)
71
+
72
+ ```typescript
73
+ // vscode-extension/src/completionProvider.ts
74
+ import {
75
+ getCompletions,
76
+ getContextualCompletions,
77
+ getCurrentWord
78
+ } from '@wire-dsl/language-support/completions';
79
+
80
+ export class WireCompletionProvider implements vscode.CompletionItemProvider {
81
+ provideCompletionItems(document, position) {
82
+ const line = document.lineAt(position.line).text;
83
+ const word = getCurrentWord(line, position.character);
84
+
85
+ // Usar completions del language-support
86
+ const suggestions = getContextualCompletions(line, word);
87
+
88
+ return suggestions.map(item => ({
89
+ label: item.label,
90
+ kind: vscode.CompletionItemKind[item.kind],
91
+ detail: item.detail,
92
+ documentation: item.documentation,
93
+ range: new vscode.Range(position, position),
94
+ }));
95
+ }
96
+ }
97
+ ```
98
+
99
+ ### Opción 2: Usar metadatos para documentación
100
+
101
+ ```typescript
102
+ // vscode-extension/src/hoverProvider.ts
103
+ import { ALL_KEYWORDS } from '@wire-dsl/language-support';
104
+
105
+ export class WireHoverProvider implements vscode.HoverProvider {
106
+ provideHover(document, position) {
107
+ const word = document.getWordRangeAtPosition(position);
108
+ const text = document.getText(word);
109
+
110
+ // Buscar en language-support
111
+ const keyword = ALL_KEYWORDS.find(k => k.name === text);
112
+ if (!keyword) return null;
113
+
114
+ return new vscode.Hover(
115
+ `**${keyword.type}**: ${keyword.description}`
116
+ );
117
+ }
118
+ }
119
+ ```
120
+
121
+ ## Instalación en VS Code Extension
122
+
123
+ ### 1. Agregar dependencia
124
+
125
+ ```bash
126
+ cd packages/vscode-extension
127
+ npm install @wire-dsl/language-support
128
+ ```
129
+
130
+ ### 2. Actualizar datos
131
+
132
+ **Antes (hardcoded):**
133
+ ```typescript
134
+ const COMPONENTS = ['button', 'text', 'input', ...];
135
+ const KEYWORDS = ['project', 'screen', 'component', ...];
136
+ ```
137
+
138
+ **Después (dinámico):**
139
+ ```typescript
140
+ import { ALL_KEYWORDS, getKeywordsByType } from '@wire-dsl/language-support';
141
+
142
+ const components = getKeywordsByType('component');
143
+ const keywords = getKeywordsByType('keyword');
144
+ ```
145
+
146
+ ## Ventajas
147
+
148
+ ✅ **Single Source of Truth** - Una única definición de lenguaje
149
+ ✅ **Menos duplicación** - Cambios se propagan automáticamente
150
+ ✅ **Consistencia** - Todos los editores usan las mismas definiciones
151
+ ✅ **Fácil mantenimiento** - Agregar componentes en un solo lugar
152
+ ✅ **OSS-friendly** - Package público y reutilizable
153
+ ✅ **Type-safe** - TypeScript types compartidos
154
+
155
+ ## Proceso de Actualización
156
+
157
+ ### Agregar un nuevo componente
158
+
159
+ 1. **Editar `packages/language-support/src/index.ts`:**
160
+ ```typescript
161
+ export const KEYWORDS: KeywordDefinition[] = [
162
+ // ... existing ...
163
+ { name: 'new-component', type: 'component', description: 'New component' },
164
+ ];
165
+ ```
166
+
167
+ 2. **Compilar el package:**
168
+ ```bash
169
+ cd packages/language-support
170
+ pnpm build
171
+ ```
172
+
173
+ 3. **Actualizar todos los dependientes:**
174
+ ```bash
175
+ cd ../web && pnpm dev # Monaco lo carga automáticamente
176
+ cd ../vscode-extension && npm run compile # VS Code Extension
177
+ ```
178
+
179
+ ## Exportes Disponibles
180
+
181
+ ```typescript
182
+ // Main package
183
+ import {
184
+ KEYWORDS,
185
+ PROPERTIES,
186
+ ALL_KEYWORDS,
187
+ getKeywordsByType,
188
+ getCompletions,
189
+ } from '@wire-dsl/language-support';
190
+
191
+ // Grammar (Monarch tokenizer)
192
+ import { MONACO_GRAMMAR, TOKENIZE_RULES } from '@wire-dsl/language-support/grammar';
193
+
194
+ // Completions (with snippets)
195
+ import {
196
+ KEYWORD_COMPLETIONS,
197
+ CONTAINER_COMPLETIONS,
198
+ COMPONENT_COMPLETIONS,
199
+ PROPERTY_COMPLETIONS,
200
+ getContextualCompletions,
201
+ isPropertyContext,
202
+ getCurrentWord,
203
+ } from '@wire-dsl/language-support/completions';
204
+ ```
205
+
206
+ ## Proximos Pasos
207
+
208
+ 1. ✅ Crear `@wire-dsl/language-support` (HECHO)
209
+ 2. ✅ Integrar con Monaco Editor (HECHO)
210
+ 3. ⏳ Integrar con VS Code Extension (Futuro)
211
+ 4. ⏳ Publicar en NPM (Futuro)
212
+ 5. ⏳ Crear Language Server Protocol (LSP) para mejor soporte
213
+
214
+ ## Recursos
215
+
216
+ - [Language Support Package](../../packages/language-support/README.md)
217
+ - [VS Code Extension Repo](https://github.com/Wire-DSL/vscode-extension)
218
+ - [Monaco Editor Docs](https://microsoft.github.io/monaco-editor/)
package/LICENSE ADDED
@@ -0,0 +1,36 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 WireDSL Contributors
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.
22
+
23
+ ---
24
+
25
+ ## Third-Party Components & Assets
26
+
27
+ ### Feather Icons
28
+
29
+ This project includes icons from Feather Icons (https://feathericons.com), created by Cole Bemis and contributors.
30
+
31
+ - **License**: MIT License
32
+ - **Repository**: https://github.com/feathericons/feather
33
+ - **Location in project**: `packages/core/src/renderer/icons/`
34
+ - **Full details**: See `packages/core/src/renderer/icons/ICONS-LICENSE.md`
35
+
36
+ Feather Icons are used under the terms of the MIT License, which is fully compatible with this project's MIT License.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # @wire-dsl/language-support
2
+
3
+ Shared language definitions for Wire DSL - used by Monaco Editor, VS Code, and CLI tools.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @wire-dsl/language-support
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { getCompletions, ALL_KEYWORDS } from '@wire-dsl/language-support';
15
+ import { MONACO_GRAMMAR } from '@wire-dsl/language-support/grammar';
16
+
17
+ // Use completions
18
+ const suggestions = getCompletions('but'); // → [button, ...]
19
+
20
+ // Use grammar for syntax highlighting
21
+ // See INTEGRATION-GUIDE.md for setup
22
+ ```
23
+
24
+ ## What's Included
25
+
26
+ - **35+ Keywords & Components** - All Wire DSL language definitions
27
+ - **Autocomplete Logic** - Context-aware suggestions
28
+ - **Syntax Grammar** - For Monaco, VS Code, and TextMate editors
29
+
30
+ ## Documentation
31
+
32
+ - **[STRATEGY.md](STRATEGY.md)** - NPM publication strategy & rationale
33
+ - **[INTEGRATION-GUIDE.md](INTEGRATION-GUIDE.md)** - How to use in your tool
34
+
35
+ ## Exports
36
+
37
+ ```typescript
38
+ // Keywords and components
39
+ export { ALL_KEYWORDS, KEYWORDS, PROPERTIES } from '@wire-dsl/language-support';
40
+ export { getCompletions, getKeywordsByType } from '@wire-dsl/language-support';
41
+
42
+ // Grammar for syntax highlighting
43
+ export { MONACO_GRAMMAR, TOKENIZE_RULES } from '@wire-dsl/language-support/grammar';
44
+
45
+ // Advanced completions
46
+ export { getContextualCompletions } from '@wire-dsl/language-support/completions';
47
+ ```
48
+
49
+ ## Published Versions
50
+
51
+ - **1.0.0** - Initial release with 35+ keywords and components
52
+
53
+ ## License
54
+
55
+ MIT - See LICENSE in root directory
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Autocomplete and IntelliSense Provider
3
+ * Shared completion logic for Monaco, VS Code, and other editors
4
+ */
5
+ export interface CompletionContext {
6
+ line: string;
7
+ position: number;
8
+ word: string;
9
+ lineText: string;
10
+ }
11
+ export interface CompletionItem {
12
+ label: string;
13
+ kind: 'Keyword' | 'Component' | 'Property' | 'Variable' | 'Value';
14
+ detail?: string;
15
+ documentation?: string;
16
+ insertText?: string;
17
+ range?: {
18
+ startColumn: number;
19
+ endColumn: number;
20
+ };
21
+ }
22
+ export type CompletionSuggestion = CompletionItem;
23
+ export declare const KEYWORD_COMPLETIONS: CompletionItem[];
24
+ export declare const CONTAINER_COMPLETIONS: CompletionItem[];
25
+ export declare const COMPONENT_COMPLETIONS: CompletionItem[];
26
+ export declare const PROPERTY_COMPLETIONS: CompletionItem[];
27
+ /**
28
+ * Detect if cursor is after 'component' keyword
29
+ * Returns component name if found, null otherwise
30
+ */
31
+ export declare function detectComponentKeyword(lineText: string): string | null;
32
+ /**
33
+ * Detect if cursor is after ':' in a property context
34
+ * Returns { propertyName, componentName } if in property value context
35
+ */
36
+ export declare function detectPropertyValueContext(lineText: string): {
37
+ propertyName: string;
38
+ componentName: string;
39
+ } | null;
40
+ /**
41
+ * Determine if we're in a property context (after ':')
42
+ */
43
+ export declare function isPropertyContext(lineText: string, position: number): boolean;
44
+ /**
45
+ * Get all available component names (built-in ones that start with uppercase)
46
+ */
47
+ export declare function getAvailableComponents(): CompletionSuggestion[];
48
+ /**
49
+ * Get properties for a specific component
50
+ */
51
+ export declare function getComponentProperties(componentName: string): CompletionSuggestion[];
52
+ /**
53
+ * Get available properties for a component
54
+ * Filters out properties already declared in current line
55
+ */
56
+ export declare function getComponentPropertiesForCompletion(componentName: string, alreadyDeclaredProps?: string[]): CompletionSuggestion[];
57
+ /**
58
+ * Get property value suggestions for a given component property
59
+ */
60
+ export declare function getPropertyValueSuggestions(componentName: string, propertyName: string): CompletionSuggestion[];
61
+ /**
62
+ * Get completions based on hierarchical scope
63
+ *
64
+ * Hierarchy:
65
+ * - empty-file: suggest 'project' to start
66
+ * - inside-project: suggest project-level keywords (screen, theme, colors, mocks, define)
67
+ * - inside-screen: suggest 'layout' keyword and containers (stack, grid, split, panel, card)
68
+ * - inside-layout: suggest components and nested layouts
69
+ */
70
+ export declare function getScopeBasedCompletions(scope: 'empty-file' | 'inside-project' | 'inside-screen' | 'inside-layout'): CompletionSuggestion[];
71
+ declare const _default: {
72
+ KEYWORD_COMPLETIONS: CompletionItem[];
73
+ CONTAINER_COMPLETIONS: CompletionItem[];
74
+ COMPONENT_COMPLETIONS: CompletionItem[];
75
+ PROPERTY_COMPLETIONS: CompletionItem[];
76
+ isPropertyContext: typeof isPropertyContext;
77
+ getComponentPropertiesForCompletion: typeof getComponentPropertiesForCompletion;
78
+ getPropertyValueSuggestions: typeof getPropertyValueSuggestions;
79
+ getScopeBasedCompletions: typeof getScopeBasedCompletions;
80
+ detectComponentKeyword: typeof detectComponentKeyword;
81
+ detectPropertyValueContext: typeof detectPropertyValueContext;
82
+ getAvailableComponents: typeof getAvailableComponents;
83
+ getComponentProperties: typeof getComponentProperties;
84
+ };
85
+ export default _default;
86
+ //# sourceMappingURL=completions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completions.d.ts","sourceRoot":"","sources":["../src/completions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,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