Skip to content

Commit

Permalink
Add Popfile wave number decorations
Browse files Browse the repository at this point in the history
  • Loading branch information
cooolbros committed Jan 9, 2025
1 parent 1c0b958 commit 4f86939
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
27 changes: 26 additions & 1 deletion packages/server/src/VDF/Popfile/PopfileLanguageServer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CombinedDataTransformer, initTRPC } from "@trpc/server"
import { firstValueFrom } from "rxjs"
import { firstValueFrom, Subscription } from "rxjs"
import { FoldingRange, FoldingRangeKind, type Connection, type FoldingRangeParams, type TextDocumentChangeEvent } from "vscode-languageserver"
import type { TextDocumentRequestParams } from "../../LanguageServer"
import { VDFLanguageServer } from "../VDFLanguageServer"
Expand Down Expand Up @@ -37,8 +37,30 @@ export class PopfileLanguageServer extends VDFLanguageServer<"popfile", PopfileT
}

protected async onDidOpen(event: TextDocumentChangeEvent<PopfileTextDocument>): Promise<{ onDidClose: () => void }> {

const { onDidClose } = await super.onDidOpen(event)

const key = await this.trpc.client.window.createTextEditorDecorationType.mutate({
options: {
after: {
margin: "0 0 0 0.5rem",
color: "#99999959",
}
}
})

const subscriptions: Subscription[] = []

subscriptions.push(
event.document.decorations$.subscribe((decorations) => {
this.trpc.client.textDocument.decoration.mutate({
uri: event.document.uri,
key: key,
decorations: decorations
})
})
)

if (this.vscript == false) {
firstValueFrom(event.document.documentSymbols$).then((documentSymbols) => {

Expand All @@ -60,6 +82,9 @@ export class PopfileLanguageServer extends VDFLanguageServer<"popfile", PopfileT
return {
onDidClose: () => {
onDidClose()
for (const subscription of subscriptions) {
subscription.unsubscribe()
}
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions packages/server/src/VDF/Popfile/PopfileTextDocument.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { VSCodeVDFConfiguration } from "common/VSCodeVDFConfiguration"
import { concatMap, map, switchMap, type Observable } from "rxjs"
import type { VDFRange } from "vdf"
import { type VDFDocumentSymbol, type VDFDocumentSymbols } from "vdf-documentsymbols"
import { CodeActionKind, CompletionItemKind, DiagnosticSeverity, InsertTextFormat } from "vscode-languageserver"
import type { Definitions } from "../../DefinitionReferences"
Expand Down Expand Up @@ -110,6 +111,8 @@ export class PopfileTextDocument extends VDFTextDocument<PopfileTextDocument, Po
}
}

public readonly decorations$: Observable<{ range: VDFRange, renderOptions: { after: { contentText: string } } }[]>

constructor(
init: TextDocumentInit,
documentConfiguration: Observable<VSCodeVDFConfiguration>,
Expand Down Expand Up @@ -155,6 +158,32 @@ export class PopfileTextDocument extends VDFTextDocument<PopfileTextDocument, Po
return definitionReferences$
}
})

this.decorations$ = this.documentSymbols$.pipe(
map((documentSymbols) => {
const waveSchedule = documentSymbols.find((documentSymbol) => documentSymbol.key != "#base" && documentSymbol)?.children
if (!waveSchedule) {
return []
}

return waveSchedule.reduce(
(decorations, documentSymbol) => {
if (documentSymbol.key.toLowerCase() == "Wave".toLowerCase() && documentSymbol.children != undefined) {
decorations.push({
range: documentSymbol.nameRange,
renderOptions: {
after: {
contentText: `${decorations.length + 1}`
}
}
})
}
return decorations
},
<{ range: VDFRange, renderOptions: { after: { contentText: string } } }[]>[]
)
})
)
}

protected validateDocumentSymbol(documentSymbol: VDFDocumentSymbol, path: VDFDocumentSymbol[], documentSymbols: VDFDocumentSymbols, definitions: Definitions): null | DiagnosticCodeAction | Observable<DiagnosticCodeAction | null> {
Expand Down

0 comments on commit 4f86939

Please sign in to comment.