Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add folding ranges for imports #2103

Open
Techatrix opened this issue Dec 7, 2024 · 0 comments
Open

add folding ranges for imports #2103

Techatrix opened this issue Dec 7, 2024 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Techatrix
Copy link
Member

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 Techatrix added enhancement New feature or request good first issue Good for newcomers labels Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant