Skip to content

[feature] format code #103

Open
Open
@Freed-Wu

Description

@Freed-Wu

Why not use iStyle to provide format function like:

https://github.com/regen100/cmake-language-server/blob/master/cmake_language_server/server.py#L156-L179:

        if shutil.which("cmake-format") is not None:

            @self.feature(TEXT_DOCUMENT_FORMATTING)
            def formatting(
                params: DocumentFormattingParams,
            ) -> Optional[List[TextEdit]]:
                doc = self.workspace.get_document(params.text_document.uri)
                content = doc.source
                formatted = subprocess.check_output(
                    ["cmake-format", "-"],
                    cwd=str(Path(doc.path).parent),
                    input=content,
                    universal_newlines=True,
                )
                lines = content.count("\n")
                return [
                    TextEdit(
                        range=Range(
                            start=Position(line=0, character=0),
                            end=Position(line=lines + 1, character=0),
                        ),
                        new_text=formatted,
                    )
                ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions