Skip to content

Conversation

@ultmaster
Copy link
Contributor

Summary

  • load context/stylesheet files when no preview options exist
  • use these defaults when validating POML documents

Testing

  • npm run build-webview
  • npm run build-cli
  • npm run lint
  • npm test
  • python -m pytest python/tests

https://chatgpt.com/codex/tasks/task_e_688ce507d084832e9c2577dcb9dca818

Copilot AI review requested due to automatic review settings August 4, 2025 08:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the POML Language Server to automatically load context and stylesheet files when no preview options exist, improving the default validation behavior for POML documents.

  • Auto-loads associated .context.json and .stylesheet.json files based on the POML file's base name
  • Replaces inline default options creation with a dedicated method for better maintainability
  • Improves diagnostics by using auto-discovered context and stylesheet files

import { PomlFile, PomlToken } from 'poml/file';
import { encodingForModel, Tiktoken } from 'js-tiktoken';
import { readFile } from 'fs/promises';
import * as fs from 'fs';
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using 'fs/promises' for consistency with the existing 'readFile' import and to avoid blocking synchronous file operations. Replace 'fs.existsSync' with 'fs.promises.access' or similar async alternatives.

Suggested change
import * as fs from 'fs';
import * as fs from 'fs/promises';

Copilot uses AI. Check for mistakes.
Comment on lines +109 to +120
private getAssociatedOptions(uri: string): WebviewUserOptions {
let options = this.associatedOptions.get(uri);
if (!options) {
const filePath = fileURLToPath(uri);
const base = filePath.replace(/(\.source)?\.poml$/i, '');
const contexts: string[] = [];
const stylesheets: string[] = [];
if (fs.existsSync(`${base}.context.json`)) {
contexts.push(`${base}.context.json`);
}
if (fs.existsSync(`${base}.stylesheet.json`)) {
stylesheets.push(`${base}.stylesheet.json`);
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using synchronous file system operations can block the event loop in a language server. Consider using async file operations with try-catch blocks or fs.promises.access() to avoid blocking operations.

Suggested change
private getAssociatedOptions(uri: string): WebviewUserOptions {
let options = this.associatedOptions.get(uri);
if (!options) {
const filePath = fileURLToPath(uri);
const base = filePath.replace(/(\.source)?\.poml$/i, '');
const contexts: string[] = [];
const stylesheets: string[] = [];
if (fs.existsSync(`${base}.context.json`)) {
contexts.push(`${base}.context.json`);
}
if (fs.existsSync(`${base}.stylesheet.json`)) {
stylesheets.push(`${base}.stylesheet.json`);
private async getAssociatedOptions(uri: string): Promise<WebviewUserOptions> {
let options = this.associatedOptions.get(uri);
if (!options) {
const filePath = fileURLToPath(uri);
const base = filePath.replace(/(\.source)?\.poml$/i, '');
const contexts: string[] = [];
const stylesheets: string[] = [];
try {
await fs.promises.access(`${base}.context.json`, fs.constants.F_OK);
contexts.push(`${base}.context.json`);
} catch (e) {
// file does not exist, do nothing
}
try {
await fs.promises.access(`${base}.stylesheet.json`, fs.constants.F_OK);
stylesheets.push(`${base}.stylesheet.json`);
} catch (e) {
// file does not exist, do nothing

Copilot uses AI. Check for mistakes.
if (fs.existsSync(`${base}.context.json`)) {
contexts.push(`${base}.context.json`);
}
if (fs.existsSync(`${base}.stylesheet.json`)) {
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using synchronous file system operations can block the event loop in a language server. Consider using async file operations with try-catch blocks or fs.promises.access() to avoid blocking operations.

Copilot uses AI. Check for mistakes.
@ultmaster ultmaster closed this Aug 5, 2025
@ultmaster ultmaster reopened this Aug 5, 2025
@ultmaster ultmaster merged commit aa10570 into main Aug 5, 2025
5 checks passed
@ultmaster ultmaster deleted the codex/auto-set-associatedoptions-for-diagnostics branch August 27, 2025 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants