Skip to content

add folding ranges for imports #2103

Open
@Techatrix

Description

@Techatrix

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions