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
6 changes: 4 additions & 2 deletions packages/api-model/src/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_.]*)*`
Expand Down Expand Up @@ -1675,14 +1675,16 @@ 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: '.' })
out.push({ text: context.name, declaration: true })
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)
Expand Down
33 changes: 33 additions & 0 deletions packages/api-model/test/clojure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']]))
Expand Down
2 changes: 1 addition & 1 deletion scripts/xref-floor.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"rs": 4330,
"go": 13216,
"java": 1672,
"clojure": 673,
"clojure": 643,
"csharp": 3182,
"cxx": 1982,
"swift": 3739,
Expand Down
25 changes: 25 additions & 0 deletions site/test/native-signature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading