diff --git a/packages/api-model/src/link.ts b/packages/api-model/src/link.ts index 36e987cac..9634c5797 100644 --- a/packages/api-model/src/link.ts +++ b/packages/api-model/src/link.ts @@ -1524,7 +1524,7 @@ export class SymbolIndex { ? String.raw`[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*!?` // A number is matched whole, so `1_000` is not a literal followed by a name. : this.lang === 'elixir' ? String.raw`\d[\d_]*(?:\.\d+)?(?:[eE][+-]?\d+)?|[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*[!?]?` - : this.lang === 'clojure' ? String.raw`::?[^\s,()[\]{}"';]+|[A-Za-z_][A-Za-z0-9_.]*(?:::[A-Za-z_][A-Za-z0-9_.]*)*` + : this.lang === 'clojure' ? String.raw`::?[^\s,()[\]{}"';]+|[A-Za-z_][A-Za-z0-9_./?!*+<>=:$%&-]*` : this.lang === 'powershell' ? String.raw`(?:[A-Za-z_][A-Za-z0-9_.]*\\)?[A-Za-z_][A-Za-z0-9_.-]*` : this.lang === 'ts' ? String.raw`[A-Za-z_$][A-Za-z0-9_$.]*` : this.lang === 'rs' ? String.raw`(?:r#)?[A-Za-z_][A-Za-z0-9_.]*(?:::(?:r#)?[A-Za-z_][A-Za-z0-9_.]*)*` @@ -1675,6 +1675,7 @@ export class SymbolIndex { } if (signature && context && (ident === context.name || ident.endsWith(`.${context.name}`)) && (/\b(?:def|fun|class|interface|trait|object|type|val|var|member|let)\s+$/.test(annotation.slice(0, m.index)) || + (this.lang === 'clojure' && annotation === signature.raw && annotation.slice(0, m.index).trim() === '(') || (this.lang === 'julia' && annotation.slice(0, m.index).trim() === '' && /^[{(]/.test(annotation.slice(m.index! + ident.length))))) { const receiver = ident.slice(0, -context.name.length).replace(/\.$/, '') if (receiver) out.push(...this.linkType(receiver, context), { text: '.' }) @@ -1682,7 +1683,8 @@ export class SymbolIndex { continue } if (signature && (signature.params.some((param) => param.name === ident) || signature.receiver?.name === ident) && - (/^\s*\??\s*:(?!:)/.test(annotation.slice(m.index! + ident.length)) || + ((this.lang === 'clojure' && annotation === signature.raw) || + /^\s*\??\s*:(?!:)/.test(annotation.slice(m.index! + ident.length)) || (this.lang === 'julia' && /(?:^|[(,;])\s*$/.test(annotation.slice(0, m.index)) && /^\s*(?:::|[=,;)]|\.\.\.)/.test(annotation.slice(m.index! + ident.length))))) { const parameter = this.lang === 'julia' && context && signature.params.some((param) => param.name === ident) diff --git a/packages/api-model/test/clojure.test.ts b/packages/api-model/test/clojure.test.ts index 5e06fb27b..191b540ac 100644 --- a/packages/api-model/test/clojure.test.ts +++ b/packages/api-model/test/clojure.test.ts @@ -41,6 +41,39 @@ function artifact() { } describe('compiled Clojure artifact', () => { + it('keeps var names and local arguments out of Java signature links', () => { + const input = artifact() + input.symbols.push( + callable('libtmux.control', 'send!', [['connection', 'argv', 'timeout']]), + callable('libtmux.data', 'one-or-none', [['values']]), + callable('libtmux.core', 'join-pane!', [['pane', 'window']]), + callable('libtmux.core', 'ready?', [['timeout-ms']]), + ) + const model = extractClojure(input, revision) + const index = new SymbolIndex(model.symbols, (symbol) => `/${symbol.id}/`, 'clojure') + index.addInventory('/en/java/latest/reference/', ['timeout', 'values', 'join', 'or', 'none'].map((name) => ({ + name, type: 'std:label', priority: 1, uri: `${name}/`, dispname: name, + })), ['clojure'], 'libtmux Java') + index.addInventory('https://docs.oracle.com/en/java/javase/25/docs/api/', [{ + name: 'java.util.concurrent.CompletionStage', type: 'std:label', priority: 1, + uri: 'java.base/java/util/concurrent/CompletionStage.html', dispname: '-', + }], ['clojure'], 'Java SE') + for (const id of ['libtmux.control/send!', 'libtmux.data/one-or-none', 'libtmux.core/join-pane!', 'libtmux.core/ready?']) { + const symbol = model.symbols.find((entry) => entry.id === id)! + const signature = symbol.signatures[0]! + const spans = index.linkType(signature.raw!, symbol, signature) + expect(spans.some((span) => span.link), signature.raw).toBe(false) + expect(spans.map((span) => span.text).join('')).toBe(signature.raw) + expect(spans.find((span) => span.text === symbol.name)?.declaration).toBe(true) + for (const parameter of signature.params) { + expect(spans.find((span) => span.text === parameter.name)?.declaration, parameter.name).toBe(true) + } + } + expect(index.linkType('java.util.concurrent.CompletionStage')[0]?.link?.href) + .toContain('java/util/concurrent/CompletionStage.html') + expect(index.docSpans('See [[libtmux.core/close!]].')[1]?.link?.symbol?.id).toBe('libtmux.core/close!') + }) + it('keeps keywords literal when their names match callable declarations', () => { const input = artifact() input.symbols.push(callable('libtmux.core', 'timeout', [['value']])) diff --git a/scripts/xref-floor.json b/scripts/xref-floor.json index 43ea21ec1..03841569e 100644 --- a/scripts/xref-floor.json +++ b/scripts/xref-floor.json @@ -11,7 +11,7 @@ "rs": 4330, "go": 13216, "java": 1672, - "clojure": 673, + "clojure": 643, "csharp": 3182, "cxx": 1982, "swift": 3739, diff --git a/site/test/native-signature.test.ts b/site/test/native-signature.test.ts index 8cf9abf54..911e9f483 100644 --- a/site/test/native-signature.test.ts +++ b/site/test/native-signature.test.ts @@ -60,6 +60,31 @@ function displayedSignature(element: Element): string { return copy.textContent ?? '' } +it('renders Clojure call arities without linking local bindings to Java methods', async () => { + const model = JSON.parse(readFileSync(new URL('../src/data/api/clojure.json', import.meta.url), 'utf8')) as ApiModel + const href = (symbol: ApiSymbol) => `/reference/${symbol.slug}/` + const index = createApiIndex(model, href) + const component = await (componentPromise ??= signatureComponent()) + const container = await experimental_AstroContainer.create() + const win = new Window() + try { + const functions = model.symbols.filter((symbol) => symbol.kind === 'function') + expect(functions.length).toBeGreaterThan(0) + for (const symbol of functions) { + for (const sig of symbol.signatures) { + win.document.body.innerHTML = await container.renderToString(component, { props: { + symbol, sig, port: 'clojure', language: 'clojure', index, + nameHref: href(symbol), nativeSignatureText, + } }) + const element = win.document.querySelector('.api-native-signature')! + expect(displayedSignature(element)).toBe(sig.raw) + expect(element.querySelector('.api-declaration-name')?.textContent).toBe(symbol.name) + expect(element.querySelectorAll('a.api-type-link'), sig.raw).toHaveLength(0) + } + } + } finally { await win.happyDOM.abort() } +}) + it('renders Erlang compiler references with exact native declarations and Markdown', async () => { const artifact = JSON.parse(readFileSync(new URL('../../packages/api-model/test/fixtures/erlang-native.json', import.meta.url), 'utf8')) const model = extractErlang(artifact)