Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions protocol/cli.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* CLI-related types
* Types that represent CLI command results and errors
*/

export interface LintError {
id: string;
message: string;
description?: string | null;
path: string;
schemaLocation: string;
position: [number, number, number, number] | null;
}

export interface LintResult {
raw: string;
health: number | null;
valid?: boolean;
errors?: LintError[];
error?: boolean;
}

export interface CommandResult {
output: string;
exitCode: number | null;
}

export interface MetaschemaError {
error: string;
instanceLocation: string;
keywordLocation: string;
absoluteKeywordLocation?: string;
instancePosition?: [number, number, number, number];
}

export interface CliError {
error: string;
line?: number;
column?: number;
filePath?: string;
identifier?: string;
location?: string;
rule?: string;
testNumber?: number;
uri?: string;
command?: string;
option?: string;
}

export interface MetaschemaResult extends CommandResult {
errors?: (MetaschemaError | CliError)[];
}

export type FormatResult = CommandResult;
61 changes: 61 additions & 0 deletions protocol/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Protocol types for communication between VSCode extension and webview
* This file defines the message passing contract
*/

import type {
LintResult,
FormatResult,
MetaschemaResult
} from './cli';

export type TabType = 'lint' | 'format' | 'metaschema';

export interface WebviewState {
activeTab?: TabType;
}

export interface FileInfo {
absolutePath: string;
displayPath: string;
fileName: string;
lineCount?: number;
isYaml?: boolean;
}

export type {
LintError,
LintResult,
CommandResult,
MetaschemaError,
CliError,
MetaschemaResult,
FormatResult
} from './cli';

export interface PanelState {
fileInfo: FileInfo | null;
cliVersion: string;
extensionVersion: string;
lintResult: LintResult;
formatResult: FormatResult;
metaschemaResult: MetaschemaResult;
isLoading?: boolean;
formatLoading?: boolean;
hasParseErrors?: boolean;
blockedByMetaschema?: boolean;
noFileSelected?: boolean;
}

export type WebviewCommand = 'goToPosition' | 'formatSchema' | 'openExternal';

export interface WebviewToExtensionMessage {
command: WebviewCommand;
position?: [number, number, number, number];
url?: string;
}

export interface ExtensionToWebviewMessage {
type: 'update';
state: PanelState;
}
82 changes: 0 additions & 82 deletions shared/types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion vscode/src/commands/CommandExecutor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawn } from 'child_process';
import { CommandResult } from '../../../shared/types';
import { CommandResult } from '../../../protocol/types';

/**
* Execute a CLI command and return the result
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/diagnostics/DiagnosticManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { DiagnosticType } from '../types';
import { LintError, CliError, MetaschemaError } from '../../../shared/types';
import { LintError, CliError, MetaschemaError } from '../../../protocol/types';
import { errorPositionToRange } from '../utils/fileUtils';

/**
Expand Down
6 changes: 3 additions & 3 deletions vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PanelManager } from './panel/PanelManager';
import { CommandExecutor } from './commands/CommandExecutor';
import { DiagnosticManager } from './diagnostics/DiagnosticManager';
import { getFileInfo, parseLintResult, parseMetaschemaResult, errorPositionToRange, parseCliError, hasJsonParseErrors } from './utils/fileUtils';
import { WebviewMessage, PanelState } from '../../shared/types';
import { PanelState, WebviewToExtensionMessage } from '../../protocol/types';
import { DiagnosticType } from './types';

let panelManager: PanelManager;
Expand Down Expand Up @@ -42,7 +42,7 @@ export function activate(context: vscode.ExtensionContext): void {
context.subscriptions.push(collection);
});

panelManager.setMessageHandler((message: WebviewMessage) => {
panelManager.setMessageHandler((message: WebviewToExtensionMessage) => {
handleWebviewMessage(message);
});

Expand Down Expand Up @@ -73,7 +73,7 @@ export function activate(context: vscode.ExtensionContext): void {
/**
* Handle messages from the webview
*/
function handleWebviewMessage(message: WebviewMessage): void {
function handleWebviewMessage(message: WebviewToExtensionMessage): void {
if (message.command === 'goToPosition' && lastActiveTextEditor && message.position) {
const range = errorPositionToRange(message.position);

Expand Down
12 changes: 6 additions & 6 deletions vscode/src/panel/PanelManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import { WebviewMessage, PanelState } from '../../../shared/types';
import { PanelState, WebviewToExtensionMessage, ExtensionToWebviewMessage } from '../../../protocol/types';

/**
* Manages the webview panel lifecycle and content
Expand All @@ -10,7 +10,7 @@ export class PanelManager {
private panel: vscode.WebviewPanel | undefined;
private readonly iconPath: vscode.Uri;
private readonly extensionPath: string;
private messageHandler?: (message: WebviewMessage) => void;
private messageHandler?: (message: WebviewToExtensionMessage) => void;

constructor(extensionPath: string) {
this.extensionPath = extensionPath;
Expand All @@ -20,7 +20,7 @@ export class PanelManager {
/**
* Set the message handler for webview messages
*/
setMessageHandler(handler: (message: WebviewMessage) => void): void {
setMessageHandler(handler: (message: WebviewToExtensionMessage) => void): void {
this.messageHandler = handler;
}

Expand Down Expand Up @@ -90,11 +90,11 @@ export class PanelManager {
return;
}

// Send state update to React webview
this.panel.webview.postMessage({
const message: ExtensionToWebviewMessage = {
type: 'update',
state: state
});
};
this.panel.webview.postMessage(message);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/utils/fileUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path';
import * as vscode from 'vscode';
import * as fs from 'fs';
import { FileInfo, LintResult, MetaschemaResult, CliError } from '../../../shared/types';
import { FileInfo, LintResult, MetaschemaResult, CliError } from '../../../protocol/types';

/**
* Parse generic CLI error response from JSON output
Expand Down
2 changes: 1 addition & 1 deletion webview/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import type { PanelState } from '../../shared/types.ts';
import type { PanelState } from '../../protocol/types';
import { vscode, type TabType } from './vscode-api';
import { FileInfo } from './components/FileInfo';
import { HealthBar } from './components/HealthBar';
Expand Down
2 changes: 1 addition & 1 deletion webview/src/components/FileInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FileInfo as FileInfoType } from '../../../shared/types.ts';
import type { FileInfo as FileInfoType } from '../../../protocol/types';

export interface FileInfoProps {
fileInfo: FileInfoType | null;
Expand Down
2 changes: 1 addition & 1 deletion webview/src/components/FormatTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CommandResult, FileInfo } from '../../../shared/types.ts';
import type { CommandResult, FileInfo } from '../../../protocol/types';
import { vscode } from '../vscode-api';
import { RawOutput } from './RawOutput';
import { Info, CheckCircle, AlertCircle, FileQuestion } from 'lucide-react';
Expand Down
2 changes: 1 addition & 1 deletion webview/src/components/HealthBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LintResult } from '../../../shared/types.ts';
import type { LintResult } from '../../../protocol/types';

export interface HealthBarProps {
lintResult: LintResult;
Expand Down
2 changes: 1 addition & 1 deletion webview/src/components/LintTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LintResult } from '../../../shared/types.ts';
import type { LintResult } from '../../../protocol/types';
import { vscode } from '../vscode-api';
import { RawOutput } from './RawOutput';
import { CheckCircle, AlertCircle, FileQuestion } from 'lucide-react';
Expand Down
2 changes: 1 addition & 1 deletion webview/src/components/LoadingSpinner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FileInfo } from '../../../shared/types.ts';
import type { FileInfo } from '../../../protocol/types';
import { AlertTriangle } from 'lucide-react';

export interface LoadingSpinnerProps {
Expand Down
2 changes: 1 addition & 1 deletion webview/src/components/MetaschemaTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MetaschemaResult, MetaschemaError } from '../../../shared/types.ts';
import type { MetaschemaResult, MetaschemaError } from '../../../protocol/types';
import { vscode } from '../vscode-api';
import { RawOutput } from './RawOutput';
import { CheckCircle, AlertTriangle, FileQuestion } from 'lucide-react';
Expand Down
2 changes: 1 addition & 1 deletion webview/src/components/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PanelState } from '../../../shared/types.ts';
import type { PanelState } from '../../../protocol/types';
import type { LucideIcon } from 'lucide-react';
import { calculateLintStatus, calculateFormatStatus, calculateMetaschemaStatus } from '../utils/tabStatus';

Expand Down
10 changes: 6 additions & 4 deletions webview/src/vscode-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type TabType = 'lint' | 'format' | 'metaschema';
import type { TabType, WebviewState, WebviewToExtensionMessage } from '../../protocol/types';

export type { TabType };

interface VSCodeAPI {
postMessage(message: unknown): void;
Expand All @@ -15,7 +17,7 @@ declare global {
class VSCodeAPIWrapper {
private readonly vsCodeApi = window.acquireVsCodeApi();

private postMessage(message: unknown): void {
private postMessage(message: WebviewToExtensionMessage): void {
this.vsCodeApi.postMessage(message);
}

Expand All @@ -32,12 +34,12 @@ class VSCodeAPIWrapper {
}

public getActiveTab(): TabType | undefined {
const state = this.vsCodeApi.getState() as { activeTab?: TabType } | undefined;
const state = this.vsCodeApi.getState() as WebviewState | undefined;
return state?.activeTab;
}

public setActiveTab(tab: TabType): void {
this.vsCodeApi.setState({ activeTab: tab });
this.vsCodeApi.setState({ activeTab: tab } satisfies WebviewState);
}
}

Expand Down