@gluonjs/language-server


@gluonjs/language-server / packages/language-server/src / GluonProjectAnalysis

Interface: GluonProjectAnalysis

Properties

bindings

readonly bindings: readonly ProjectEvidence<{ kind: "property" | "event" | "attribute" | "child"; name?: string; }>[]


components

readonly components: readonly ProjectEvidence<{ kind: "function" | "class"; name: string; }>[]


diagnostics

readonly diagnostics: readonly ProjectAnalysisDiagnostic[]


elements

readonly elements: readonly ProjectEvidence<{ events: readonly string[]; properties: readonly string[]; slots: readonly string[]; tagName: string; }>[]


files

readonly files: readonly ProjectEvidence<{ language: "typescript" | "javascript"; }>[]


routes

readonly routes: readonly ProjectEvidence<{ path?: string; }>[]


schemaVersion

readonly schemaVersion: 1


ssrBoundaries

readonly ssrBoundaries: readonly ProjectEvidence<{ api: string; }>[]


stores

readonly stores: readonly ProjectEvidence<{ name?: string; }>[]


styles

readonly styles: readonly ProjectEvidence<{ kind: "constructable-template" | "module-import"; source?: string; }>[]


templates

readonly templates: readonly ProjectEvidence<{ kind: "html" | "svg" | "css" | "compose"; }>[]

Example

Consume the complete immutable version-1 static project inventory grouped by supported evidence category:

ts
import {
  GluonLanguageService,
  PROJECT_ANALYSIS_SCHEMA,
  analyzeGluonDocument,
  analyzeGluonProject,
  analyzeStaticGluonProject,
  declarationsFromCustomElementsManifest,
  type CompletionItem,
  type CustomElementDeclaration,
  type DocumentAnalysis,
  type GluonProjectAnalysis,
  type Hover,
  type Location,
  type Position,
  type ProjectDocument,
  type ProjectAnalysisDiagnostic,
  type ProjectEvidence,
  type Range,
  type TemplateDiagnostic,
  type TemplateDiagnosticCode,
  type TextEdit,
  type WorkspaceEdit,
  type AnalysisConfidence,
} from '@gluonjs/language-server';

const component = {
  uri: 'file:///src/product-card.ts',
  text: `import { GluonElement, defineElement, html } from '@gluonjs/core';
    class ProductCard extends GluonElement {
      static properties = { name: String };
      static events = { select: {} };
      protected render() { return html\`<button>Product</button>\`; }
    }
    defineElement('product-card', ProductCard);`,
} satisfies ProjectDocument;
const page = {
  uri: 'file:///src/page.ts',
  text: `import { html } from '@gluonjs/core'; export const Page = () => html\`<product-card .name=\${'Lamp'}></product-card>\`;`,
} satisfies ProjectDocument;
const project: readonly DocumentAnalysis[] = analyzeGluonProject([component, page]);
const inventory: GluonProjectAnalysis = analyzeStaticGluonProject([component, page]);
const confidence: AnalysisConfidence | undefined = inventory.files[0]?.confidence;
const evidence: ProjectEvidence<{ readonly language: 'javascript' | 'typescript' }> | undefined = inventory.files[0];
const projectDiagnostic: ProjectAnalysisDiagnostic | undefined = inventory.diagnostics[0];
const schemaVersion = PROJECT_ANALYSIS_SCHEMA.properties.schemaVersion.const;
const direct = analyzeGluonDocument(page.uri, page.text, project[0]?.declarations);
const declaration: CustomElementDeclaration | undefined = project[0]?.declarations[0];
const diagnostic: TemplateDiagnostic | undefined = direct.diagnostics[0];
const code: TemplateDiagnosticCode | undefined = diagnostic?.code;

const manifestDeclarations = declarationsFromCustomElementsManifest('file:///custom-elements.json', {
  modules: [{ declarations: [{ customElement: true, tagName: 'price-tag', members: [{ kind: 'field', name: 'value' }] }] }],
});
const service = new GluonLanguageService();
service.open(component.uri, component.text);
service.open(page.uri, page.text);
const position = { line: 0, character: page.text.indexOf('product-card') } satisfies Position;
const range = { start: position, end: { ...position, character: position.character + 12 } } satisfies Range;
const completions: readonly CompletionItem[] = service.complete(page.uri, position);
const hover: Hover | undefined = service.hover(page.uri, position);
const locations: readonly Location[] = service.definition(page.uri, position);
const edit: WorkspaceEdit | undefined = service.rename(page.uri, position, 'catalog-card');
const textEdit: TextEdit = { range, newText: 'catalog-card' };
console.log(declaration, code, manifestDeclarations, completions, hover, locations, edit, textEdit, confidence, evidence, projectDiagnostic, schemaVersion);