diff --git a/packages/server/src/VDF/Popfile/PopfileLanguageServer.ts b/packages/server/src/VDF/Popfile/PopfileLanguageServer.ts index 0bec2f8c..1e1a48e8 100644 --- a/packages/server/src/VDF/Popfile/PopfileLanguageServer.ts +++ b/packages/server/src/VDF/Popfile/PopfileLanguageServer.ts @@ -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" @@ -37,8 +37,30 @@ export class PopfileLanguageServer extends VDFLanguageServer<"popfile", PopfileT } protected async onDidOpen(event: TextDocumentChangeEvent): 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) => { @@ -60,6 +82,9 @@ export class PopfileLanguageServer extends VDFLanguageServer<"popfile", PopfileT return { onDidClose: () => { onDidClose() + for (const subscription of subscriptions) { + subscription.unsubscribe() + } } } } diff --git a/packages/server/src/VDF/Popfile/PopfileTextDocument.ts b/packages/server/src/VDF/Popfile/PopfileTextDocument.ts index 793e6a2f..5502b6ac 100644 --- a/packages/server/src/VDF/Popfile/PopfileTextDocument.ts +++ b/packages/server/src/VDF/Popfile/PopfileTextDocument.ts @@ -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" @@ -110,6 +111,8 @@ export class PopfileTextDocument extends VDFTextDocument + constructor( init: TextDocumentInit, documentConfiguration: Observable, @@ -155,6 +158,32 @@ export class PopfileTextDocument extends VDFTextDocument { + 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 {