Skip to content

Commit

Permalink
dedupe identical jsdoc tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiamanzati committed Oct 11, 2024
1 parent 2d192bf commit b75985a
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-apes-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/language-service": minor
---

Dedupe identical JSDoc tags in hover quickinfo
30 changes: 30 additions & 0 deletions docs/modules/quickinfo.ts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: quickinfo.ts
nav_order: 3
parent: Modules
---

## quickinfo overview

Added in v1.0.0

---

<h2 class="text-delta">Table of contents</h2>

- [utils](#utils)
- [dedupeJsDocTags](#dedupejsdoctags)

---

# utils

## dedupeJsDocTags

**Signature**

```ts
export declare function dedupeJsDocTags(quickInfo: ts.QuickInfo): ts.QuickInfo
```

Added in v1.0.0
2 changes: 1 addition & 1 deletion docs/modules/refactors.ts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: refactors.ts
nav_order: 3
nav_order: 4
parent: Modules
---

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/transformer.ts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: transformer.ts
nav_order: 4
nav_order: 5
parent: Modules
---

Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { pipe } from "effect/Function"
import * as O from "effect/Option"
import type ts from "typescript"
import type { PluginOptions } from "./definition.js"
import { dedupeJsDocTags } from "./quickinfo.js"
import { refactors } from "./refactors.js"
import * as AST from "./utils/AST.js"

Expand Down Expand Up @@ -132,6 +133,16 @@ const init = (
)
}

proxy.getQuickInfoAtPosition = (fileName, position, ...args) => {
const quickInfo = languageService.getQuickInfoAtPosition(fileName, position, ...args)

if (quickInfo) {
return dedupeJsDocTags(quickInfo)
}

return quickInfo
}

return proxy
}

Expand Down
28 changes: 28 additions & 0 deletions src/quickinfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @since 1.0.0
*/
import * as Eq from "effect/Equivalence"
import * as A from "effect/ReadonlyArray"
import type ts from "typescript"

const SymbolDisplayPartEq = Eq.make<ts.SymbolDisplayPart>((fa, fb) =>
fa.kind === fb.kind && fa.text === fb.text
)

const JSDocTagInfoEq = Eq.make<ts.JSDocTagInfo>((fa, fb) =>
fa.name === fb.name && typeof fa.text === typeof fb.text &&
(typeof fa.text !== "undefined" ? Eq.array(SymbolDisplayPartEq)(fa.text!, fb.text!) : true)
)

/**
* @since 1.0.0
*/
export function dedupeJsDocTags(quickInfo: ts.QuickInfo): ts.QuickInfo {
if (quickInfo.tags) {
return {
...quickInfo,
tags: A.dedupeWith(quickInfo.tags, JSDocTagInfoEq)
}
}
return quickInfo
}

0 comments on commit b75985a

Please sign in to comment.