@coherent.js/language-server 1.0.0-beta.1

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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/dist/analysis/coherent-analyzer.d.ts +93 -0
  3. package/dist/analysis/coherent-analyzer.d.ts.map +1 -0
  4. package/dist/analysis/coherent-analyzer.js +288 -0
  5. package/dist/analysis/coherent-analyzer.js.map +1 -0
  6. package/dist/analysis/element-validator.d.ts +45 -0
  7. package/dist/analysis/element-validator.d.ts.map +1 -0
  8. package/dist/analysis/element-validator.js +84 -0
  9. package/dist/analysis/element-validator.js.map +1 -0
  10. package/dist/analysis/nesting-validator.d.ts +49 -0
  11. package/dist/analysis/nesting-validator.d.ts.map +1 -0
  12. package/dist/analysis/nesting-validator.js +68 -0
  13. package/dist/analysis/nesting-validator.js.map +1 -0
  14. package/dist/data/element-attributes.d.ts +92 -0
  15. package/dist/data/element-attributes.d.ts.map +1 -0
  16. package/dist/data/element-attributes.generated.json +7085 -0
  17. package/dist/data/element-attributes.js +282 -0
  18. package/dist/data/element-attributes.js.map +1 -0
  19. package/dist/data/nesting-rules.d.ts +67 -0
  20. package/dist/data/nesting-rules.d.ts.map +1 -0
  21. package/dist/data/nesting-rules.js +240 -0
  22. package/dist/data/nesting-rules.js.map +1 -0
  23. package/dist/providers/code-actions.d.ts +15 -0
  24. package/dist/providers/code-actions.d.ts.map +1 -0
  25. package/dist/providers/code-actions.js +191 -0
  26. package/dist/providers/code-actions.js.map +1 -0
  27. package/dist/providers/completion.d.ts +15 -0
  28. package/dist/providers/completion.d.ts.map +1 -0
  29. package/dist/providers/completion.js +247 -0
  30. package/dist/providers/completion.js.map +1 -0
  31. package/dist/providers/diagnostics.d.ts +26 -0
  32. package/dist/providers/diagnostics.d.ts.map +1 -0
  33. package/dist/providers/diagnostics.js +143 -0
  34. package/dist/providers/diagnostics.js.map +1 -0
  35. package/dist/providers/hover.d.ts +15 -0
  36. package/dist/providers/hover.d.ts.map +1 -0
  37. package/dist/providers/hover.js +215 -0
  38. package/dist/providers/hover.js.map +1 -0
  39. package/dist/server.d.ts +17 -0
  40. package/dist/server.d.ts.map +1 -0
  41. package/dist/server.js +82 -0
  42. package/dist/server.js.map +1 -0
  43. package/package.json +53 -0
@@ -0,0 +1,68 @@
1
+ /**
2
+ * HTML Nesting Validator
3
+ *
4
+ * Validates parent/child relationships of Coherent.js elements
5
+ * against HTML5 content model rules.
6
+ */
7
+ import { validateNesting as checkNesting } from '../data/nesting-rules.js';
8
+ /**
9
+ * Validate nesting of an element within its parent.
10
+ *
11
+ * @param element - The Coherent element to validate
12
+ * @returns Array of nesting validation errors
13
+ */
14
+ export function validateElementNesting(element) {
15
+ const errors = [];
16
+ // Check this element against its parent
17
+ const parentTag = element.parent?.tagName || null;
18
+ const nestingErrors = checkNesting(element.tagName, parentTag);
19
+ for (const error of nestingErrors) {
20
+ errors.push({
21
+ message: error.message,
22
+ range: element.tagNameRange,
23
+ code: error.code,
24
+ severity: error.severity,
25
+ childTag: element.tagName,
26
+ parentTag: parentTag || 'root',
27
+ data: {
28
+ childTag: element.tagName,
29
+ parentTag: parentTag || 'root',
30
+ },
31
+ });
32
+ }
33
+ return errors;
34
+ }
35
+ /**
36
+ * Validate nesting for multiple elements.
37
+ *
38
+ * @param elements - Array of Coherent elements to validate
39
+ * @returns Array of all nesting validation errors
40
+ */
41
+ export function validateAllNesting(elements) {
42
+ const errors = [];
43
+ for (const element of elements) {
44
+ errors.push(...validateElementNesting(element));
45
+ }
46
+ return errors;
47
+ }
48
+ /**
49
+ * Get suggestions for fixing nesting errors.
50
+ *
51
+ * @param error - The nesting validation error
52
+ * @returns Suggested fix description or null
53
+ */
54
+ export function getNestingFixSuggestion(error) {
55
+ switch (error.code) {
56
+ case 'invalid-parent':
57
+ return `Move <${error.childTag}> to be a child of the correct parent element`;
58
+ case 'invalid-nesting':
59
+ return `Remove <${error.childTag}> from <${error.parentTag}> or restructure the component`;
60
+ case 'block-in-inline':
61
+ return `Consider using a block-level container instead of <${error.parentTag}>`;
62
+ case 'invalid-child':
63
+ return `<${error.parentTag}> should not contain <${error.childTag}>`;
64
+ default:
65
+ return null;
66
+ }
67
+ }
68
+ //# sourceMappingURL=nesting-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nesting-validator.js","sourceRoot":"","sources":["../../src/analysis/nesting-validator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,eAAe,IAAI,YAAY,EAAmB,MAAM,0BAA0B,CAAC;AA4B5F;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAA4B;IACjE,MAAM,MAAM,GAA6B,EAAE,CAAC;IAE5C,wCAAwC;IACxC,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,EAAE,OAAO,IAAI,IAAI,CAAC;IAClD,MAAM,aAAa,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAE/D,KAAK,MAAM,KAAK,IAAI,aAAa,EAAE,CAAC;QAClC,MAAM,CAAC,IAAI,CAAC;YACV,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,KAAK,EAAE,OAAO,CAAC,YAAY;YAC3B,IAAI,EAAE,KAAK,CAAC,IAAsC;YAClD,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,QAAQ,EAAE,OAAO,CAAC,OAAO;YACzB,SAAS,EAAE,SAAS,IAAI,MAAM;YAC9B,IAAI,EAAE;gBACJ,QAAQ,EAAE,OAAO,CAAC,OAAO;gBACzB,SAAS,EAAE,SAAS,IAAI,MAAM;aAC/B;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAA+B;IAChE,MAAM,MAAM,GAA6B,EAAE,CAAC;IAE5C,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAA6B;IACnE,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,gBAAgB;YACnB,OAAO,SAAS,KAAK,CAAC,QAAQ,+CAA+C,CAAC;QAEhF,KAAK,iBAAiB;YACpB,OAAO,WAAW,KAAK,CAAC,QAAQ,WAAW,KAAK,CAAC,SAAS,gCAAgC,CAAC;QAE7F,KAAK,iBAAiB;YACpB,OAAO,sDAAsD,KAAK,CAAC,SAAS,GAAG,CAAC;QAElF,KAAK,eAAe;YAClB,OAAO,IAAI,KAAK,CAAC,SAAS,yBAAyB,KAAK,CAAC,QAAQ,GAAG,CAAC;QAEvE;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Element attribute data for the Coherent.js Language Server
3
+ *
4
+ * This module provides runtime access to HTML element attribute information,
5
+ * imported from the generated JSON file created by extract-attributes.ts.
6
+ *
7
+ * The data is extracted at build time from packages/core/types/elements.d.ts
8
+ * to maintain a single source of truth for element definitions.
9
+ */
10
+ export interface AttributeInfo {
11
+ name: string;
12
+ type: string;
13
+ optional: boolean;
14
+ description?: string;
15
+ }
16
+ export interface ElementInfo {
17
+ tagName: string;
18
+ attributes: AttributeInfo[];
19
+ isVoidElement: boolean;
20
+ }
21
+ export interface ExtractedData {
22
+ elements: Record<string, ElementInfo>;
23
+ voidElements: string[];
24
+ globalAttributes: AttributeInfo[];
25
+ eventHandlers: AttributeInfo[];
26
+ generatedAt: string;
27
+ }
28
+ /**
29
+ * Set of all valid HTML element tag names.
30
+ */
31
+ export declare const HTML_ELEMENTS: Set<string>;
32
+ /**
33
+ * Set of void elements that cannot have children.
34
+ */
35
+ export declare const VOID_ELEMENTS: Set<string>;
36
+ /**
37
+ * Get all valid attributes for a given HTML element.
38
+ *
39
+ * Returns element-specific attributes combined with global attributes,
40
+ * event handlers, and Coherent.js properties.
41
+ *
42
+ * @param tagName - The HTML element tag name (e.g., 'div', 'input')
43
+ * @returns Array of attribute information
44
+ */
45
+ export declare function getAttributesForElement(tagName: string): AttributeInfo[];
46
+ /**
47
+ * Check if an element is a void element (cannot have children).
48
+ *
49
+ * @param tagName - The HTML element tag name
50
+ * @returns true if the element is a void element
51
+ */
52
+ export declare function isVoidElement(tagName: string): boolean;
53
+ /**
54
+ * Check if an attribute is valid for a given element.
55
+ *
56
+ * @param tagName - The HTML element tag name
57
+ * @param attributeName - The attribute name to check
58
+ * @returns true if the attribute is valid for the element
59
+ */
60
+ export declare function isValidAttribute(tagName: string, attributeName: string): boolean;
61
+ /**
62
+ * Get suggestions for a potentially misspelled attribute name.
63
+ *
64
+ * Uses Levenshtein distance to find similar attribute names.
65
+ *
66
+ * @param tagName - The HTML element tag name
67
+ * @param attributeName - The potentially misspelled attribute name
68
+ * @param maxDistance - Maximum edit distance for suggestions (default: 3)
69
+ * @returns Array of suggested attribute names, sorted by distance
70
+ */
71
+ export declare function getSuggestions(tagName: string, attributeName: string, maxDistance?: number): string[];
72
+ /**
73
+ * Get the type description for an attribute.
74
+ *
75
+ * @param tagName - The HTML element tag name
76
+ * @param attributeName - The attribute name
77
+ * @returns Type string or undefined if attribute not found
78
+ */
79
+ export declare function getAttributeType(tagName: string, attributeName: string): string | undefined;
80
+ /**
81
+ * Get the description for an attribute.
82
+ *
83
+ * @param tagName - The HTML element tag name
84
+ * @param attributeName - The attribute name
85
+ * @returns Description string or undefined if not available
86
+ */
87
+ export declare function getAttributeDescription(tagName: string, attributeName: string): string | undefined;
88
+ /**
89
+ * Get element-specific description for hover documentation.
90
+ */
91
+ export declare function getElementDescription(tagName: string): string;
92
+ //# sourceMappingURL=element-attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-attributes.d.ts","sourceRo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