Skip to content
Open
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
65 changes: 0 additions & 65 deletions docs/workflows/2026-07-21-clip-scintilla-margin.md

This file was deleted.

36 changes: 0 additions & 36 deletions docs/workflows/2026-07-21-disable-scintilla-line-scroll-snap.md

This file was deleted.

38 changes: 0 additions & 38 deletions docs/workflows/2026-07-21-match-scintilla-bounce-background.md

This file was deleted.

45 changes: 0 additions & 45 deletions docs/workflows/2026-07-21-prevent-scintilla-first-frame-flash.md

This file was deleted.

8 changes: 8 additions & 0 deletions lynxtron-go/src/extension-host/__tests__/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ import { useState } from '@lynx-js/react';

export function App() {
const [count] = useState(1);
const interval = setInterval(() => console.log(count), 1000);
const timeout = setTimeout(() => clearInterval(interval), 1000);
clearTimeout(timeout);
return <view><text>{count}</text></view>;
}
`);
Expand All @@ -320,6 +323,11 @@ root.render(<App />);

expect(markers.some(m => m.code === 2875)).toBe(false);
expect(markers.some(m => m.code === 2307)).toBe(false);
expect(markers.some(m => m.message.includes("Cannot find name 'setInterval'"))).toBe(false);
expect(markers.some(m => m.message.includes("Cannot find name 'clearInterval'"))).toBe(false);
expect(markers.some(m => m.message.includes("Cannot find name 'setTimeout'"))).toBe(false);
expect(markers.some(m => m.message.includes("Cannot find name 'clearTimeout'"))).toBe(false);
expect(markers.some(m => m.message.includes("Cannot find name 'console'"))).toBe(false);
expect(markers.filter(m => m.severity === 'error')).toHaveLength(0);
} finally {
fs.rmSync(tempRoot, { recursive: true, force: true });
Expand Down
48 changes: 48 additions & 0 deletions lynxtron-go/src/extension-host/language-server/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@ interface FileEntry {
content: string;
}

const LYNX_GLOBALS_WORKAROUND_FILE = '.lynxtron-go-lynx-globals.d.ts';
const LYNX_GLOBALS_WORKAROUND_SOURCE = `
export {};

declare global {
interface Console {
debug(...args: any[]): void;
error(...args: any[]): void;
group(label?: string): void;
groupEnd(): void;
info(...args: any[]): void;
log(...args: any[]): void;
alog(...args: any[]): void;
warn(...args: any[]): void;
}

var console: Console;

function setTimeout(callback: (...args: unknown[]) => unknown, delay: number): number;
function setInterval(callback: (...args: unknown[]) => unknown, delay: number): number;
function clearTimeout(timeoutId: number): void;
function clearInterval(timeoutId: number): void;
}
`;

interface ProjectConfig {
key: string;
projectRoot: string;
Expand Down Expand Up @@ -236,6 +261,16 @@ function shouldUseBundledModuleFallback(
return /\.(?:[cm]?js|jsx)$/.test(resolved.resolvedFileName);
}

function needsLynxGlobalsWorkaround(options: ts.CompilerOptions): boolean {
if (!options.types?.includes('@lynx-js/types')) return false;

// An omitted lib list uses TypeScript's defaults, which already include DOM.
// Lynx app configs explicitly choose an ES-only lib to avoid browser globals.
if (!options.lib) return false;

return !options.lib.some((libPath) => path.basename(libPath).toLowerCase() === 'lib.dom.d.ts');
}

class LanguageServiceHost implements ts.LanguageServiceHost {
private files = new Map<string, FileEntry>();
private rootFiles: string[];
Expand All @@ -253,6 +288,16 @@ class LanguageServiceHost implements ts.LanguageServiceHost {
this.options = options;
this.rootFiles = [...new Set(rootFiles)];
this.bundledFallback = bundledFallback;

// @lynx-js/types@3.8 declares the timer functions outside declare global
// and exports Console without declaring the global console variable. Keep
// Lynx projects free of DOM types while making the runtime globals visible.
if (needsLynxGlobalsWorkaround(options)) {
this.files.set(path.join(projectRoot, LYNX_GLOBALS_WORKAROUND_FILE), {
version: 0,
content: LYNX_GLOBALS_WORKAROUND_SOURCE,
});
}
}

updateFile(filePath: string, content: string, version: number) {
Expand Down Expand Up @@ -294,10 +339,13 @@ class LanguageServiceHost implements ts.LanguageServiceHost {
}

fileExists(path: string): boolean {
if (this.files.has(path)) return true;
return ts.sys.fileExists(path);
}

readFile(path: string): string | undefined {
const entry = this.files.get(path);
if (entry) return entry.content;
return ts.sys.readFile(path);
}

Expand Down