zls icon indicating copy to clipboard operation
zls copied to clipboard

add folding ranges for imports

Open Techatrix opened this issue 1 year ago • 0 comments

Zig files usually begin with a bunch of @imports like this:

const std = @import("std");
const Ast = std.zig.Ast;

const Server = @import("../Server.zig");
const DocumentStore = @import("../DocumentStore.zig");
const types = @import("lsp").types;
const Analyser = @import("../analysis.zig");
const ast = @import("../ast.zig");
const offsets = @import("../offsets.zig");
const tracy = @import("tracy");
const URI = @import("../uri.zig");
const DocumentScope = @import("../DocumentScope.zig");
const analyser_completions = @import("../analyser/completions.zig");

const data = @import("version_data");
const snipped_data = @import("../snippets.zig");

ZLS should offer to collapse them into one line like other declarations. Here is an example of folding ranges in VS Code: Screenshot From 2024-12-07 21-06-49

Care must be taken to ensure that only "imports" or "aliases" are collapsed and no other declarations. The source.organizeImports code action has dealt with a similar task here.

The implementation of folding ranges can be found in src/features/folding_range.zig. The LSP specification for textDocument/foldingRange can also be useful.

Techatrix avatar Dec 07 '24 20:12 Techatrix