Skip to content

Commit

Permalink
Merge pull request 'fix: consider the length of the ReferenceToken te…
Browse files Browse the repository at this point in the history
…xt' from fix/formatter into develop

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/api.onlyoffice.com/pulls/114
Reviewed-by: Ivan Uhalin <[email protected]>
  • Loading branch information
LinneyS committed Jan 13, 2025
2 parents 22db48a + cee40cb commit 9b1dc9e
Show file tree
Hide file tree
Showing 4 changed files with 223 additions and 8 deletions.
16 changes: 16 additions & 0 deletions packages/typedoc-signature/fixtures/036/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
interface FirstInterface {}
interface SecondInterface {}
interface ThirdInterface {}
interface FourthInterface {}
interface FifthInterface {}
interface SixthInterface {}

interface I {
p0:
| FirstInterface
| SecondInterface
| ThirdInterface
| FourthInterface
| FifthInterface
| SixthInterface
}
190 changes: 190 additions & 0 deletions packages/typedoc-signature/fixtures/036/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import { DeclarationEntity } from "@onlyoffice/library-declaration/next.js"
import {
EntityToken,
KeywordToken,
ParameterToken,
Reference,
type Signature,
TextToken,
type Token,
TypeToken,
} from "@onlyoffice/signature"

export const name = "computing the signature for an interface with a parameter with a string length of more than 100 characters and whose types are Reference"
export const collection: DeclarationEntity[] = []

const e0 = new DeclarationEntity()
let s: Signature = []
let t: Token | Reference

e0.id = 5

t = new KeywordToken()
t.text = "interface"
s.push(t)

t = new TextToken()
t.text = " "
s.push(t)

t = new EntityToken()
t.text = "I"
s.push(t)

t = new TextToken()
t.text = " "
s.push(t)

t = new TextToken()
t.text = "{"
s.push(t)

t = new TextToken()
t.text = "\n"
s.push(t)

t = new TextToken()
t.text = " "
s.push(t)

t = new ParameterToken()
t.text = "p0"
s.push(t)

t = new TextToken()
t.text = ": "
s.push(t)

t = new TextToken()
t.text = "\n"
s.push(t)

t = new TextToken()
t.text = " "
s.push(t)

t = new Reference()
t.id = "3"
t.token = new TypeToken()
t.token.text = "FirstInterface"
s.push(t)

t = new TextToken()
t.text = " | "
s.push(t)

t = new TextToken()
t.text = "\n"
s.push(t)

t = new TextToken()
t.text = " "
s.push(t)

t = new Reference()
t.id = "8"
t.token = new TypeToken()
t.token.text = "SecondInterface"
s.push(t)

t = new TextToken()
t.text = " | "
s.push(t)

t = new TextToken()
t.text = "\n"
s.push(t)

t = new TextToken()
t.text = " "
s.push(t)

t = new Reference()
t.id = "10"
t.token = new TypeToken()
t.token.text = "ThirdInterface"
s.push(t)

t = new TextToken()
t.text = " | "
s.push(t)

t = new TextToken()
t.text = "\n"
s.push(t)

t = new TextToken()
t.text = " "
s.push(t)

t = new Reference()
t.id = "4"
t.token = new TypeToken()
t.token.text = "FourthInterface"
s.push(t)

t = new TextToken()
t.text = " | "
s.push(t)

t = new TextToken()
t.text = "\n"
s.push(t)

t = new TextToken()
t.text = " "
s.push(t)

t = new Reference()
t.id = "2"
t.token = new TypeToken()
t.token.text = "FifthInterface"
s.push(t)

t = new TextToken()
t.text = " | "
s.push(t)

t = new TextToken()
t.text = "\n"
s.push(t)

t = new TextToken()
t.text = " "
s.push(t)

t = new Reference()
t.id = "9"
t.token = new TypeToken()
t.token.text = "SixthInterface"
s.push(t)

t = new TextToken()
t.text = "\n"
s.push(t)

t = new TextToken()
t.text = ""
s.push(t)

t = new TextToken()
t.text = "}"
s.push(t)

e0.declaration.signature.verbose.push(...s)
s = []

t = new TextToken()
t.text = " "
s.push(t)

t = new Reference()
t.id = "5"
t.token = new TypeToken()
t.token.text = "I"
s.push(t)

e0.declaration.signature.concise.push(...s)
s = []

collection.push(e0)
3 changes: 3 additions & 0 deletions packages/typedoc-signature/fixtures/036/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exclude": ["test.ts"]
}
22 changes: 14 additions & 8 deletions packages/typedoc-signature/lib/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ export class Formatter {
let f = false // has a formatted signature in the child elements

for (const t of s) {
if (!(t instanceof Reference || t instanceof NoopToken)) {
if (t instanceof NewlineToken || t instanceof IndentToken) {
if (t.processed) {
f = true
break
}
t.processed = true
if (t instanceof NewlineToken || t instanceof IndentToken) {
if (t.processed) {
f = true
break
}
t.processed = true
} else {
let ct: Token
if (t instanceof Reference) {
ct = t.token
} else {
l += t.text.length
ct = t
}
if (!(ct instanceof Reference || ct instanceof NoopToken)) {
l += ct.text.length
}
}
}
Expand Down

0 comments on commit 9b1dc9e

Please sign in to comment.