From 6e9ce63f2f1d027823c36dc35f9e2ecb89682117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20P=C3=A1ll=20Geirsson?= Date: Thu, 15 Jul 2021 16:27:08 +0200 Subject: [PATCH] Remove unused folding ranges The emitted folding ranges could be very large and cause LSIF processing issues. This feature isn't used on Sourcegraph so it's safe to remove it. --- src/graph.ts | 22 --------------------- src/lsif.ts | 55 ---------------------------------------------------- 2 files changed, 77 deletions(-) diff --git a/src/graph.ts b/src/graph.ts index d9c6b4cd..875fcef3 100644 --- a/src/graph.ts +++ b/src/graph.ts @@ -36,8 +36,6 @@ import { textDocument_implementation, textDocument_typeDefinition, TypeDefinitionResult, - FoldingRangeResult, - textDocument_foldingRange, RangeBasedDocumentSymbol, DefinitionTag, DefinitionRange, @@ -228,14 +226,6 @@ export class VertexBuilder { } } - public foldingRangeResult(values: lsp.FoldingRange[]): FoldingRangeResult { - return { - id: this.nextId(), - type: ElementTypes.vertex, - label: VertexLabels.foldingRangeResult, - result: values, - } - } public hoverResult(value: lsp.Hover): HoverResult public hoverResult( @@ -403,18 +393,6 @@ export class EdgeBuilder { } } - public foldingRange( - from: Document, - to: FoldingRangeResult - ): textDocument_foldingRange { - return { - id: this.nextId(), - type: ElementTypes.edge, - label: EdgeLabels.textDocument_foldingRange, - outV: from.id, - inV: to.id, - } - } public diagnostic( from: Project | Document, diff --git a/src/lsif.ts b/src/lsif.ts index b8765a8f..f26b23a9 100644 --- a/src/lsif.ts +++ b/src/lsif.ts @@ -126,40 +126,6 @@ namespace Converter { } } - export function asFoldingRange( - this: void, - file: ts.SourceFile, - span: ts.OutliningSpan - ): lsp.FoldingRange { - let kind = getFoldingRangeKind(span) - let start = file.getLineAndCharacterOfPosition(span.textSpan.start) - let end = file.getLineAndCharacterOfPosition( - span.textSpan.start + span.textSpan.length - ) - return { - kind, - startLine: start.line, - startCharacter: start.character, - endLine: end.line, - endCharacter: end.character, - } as lsp.FoldingRange - } - - function getFoldingRangeKind( - span: ts.OutliningSpan - ): lsp.FoldingRangeKind | undefined { - switch (span.kind) { - case 'comment': - return lsp.FoldingRangeKind.Comment - case 'region': - return lsp.FoldingRangeKind.Region - case 'imports': - return lsp.FoldingRangeKind.Imports - case 'code': - default: - return undefined - } - } const symbolKindMap: Map = new Map< number, @@ -302,7 +268,6 @@ class ProjectData extends LSIFData { class DocumentData extends LSIFData { private ranges: Range[] private diagnostics: lsp.Diagnostic[] | undefined - private foldingRanges: lsp.FoldingRange[] | undefined private documentSymbols: RangeBasedDocumentSymbol[] | undefined public constructor( @@ -329,9 +294,6 @@ class DocumentData extends LSIFData { this.diagnostics = diagnostics } - public addFoldingRanges(foldingRanges: lsp.FoldingRange[]): void { - this.foldingRanges = foldingRanges - } public addDocumentSymbols(documentSymbols: RangeBasedDocumentSymbol[]): void { this.documentSymbols = documentSymbols @@ -346,11 +308,6 @@ class DocumentData extends LSIFData { this.emit(dr) this.emit(this.edge.diagnostic(this.document, dr)) } - if (this.foldingRanges !== undefined) { - const fr = this.vertex.foldingRangeResult(this.foldingRanges) - this.emit(fr) - this.emit(this.edge.foldingRange(this.document, fr)) - } if (this.documentSymbols !== undefined) { const ds = this.vertex.documentSymbolResult(this.documentSymbols) this.emit(ds) @@ -2292,18 +2249,6 @@ class Visitor implements ResolverContext { documentData.addDiagnostics(diagnostics) } - // Folding ranges - let spans = this.languageService.getOutliningSpans(sourceFile as any) - if (ts.textSpanEnd.length > 0) { - let foldingRanges: lsp.FoldingRange[] = [] - for (let span of spans) { - foldingRanges.push(Converter.asFoldingRange(sourceFile, span)) - } - if (foldingRanges.length > 0) { - documentData.addFoldingRanges(foldingRanges) - } - } - // Document symbols. let values = (this.symbolContainer.pop() as RangeBasedDocumentSymbol) .children