Giter VIP home page Giter VIP logo

Comments (9)

IC0hO avatar IC0hO commented on July 21, 2024 1

I see, thank you, your nvim-config has helped me a lot.

from nvim-config.

IC0hO avatar IC0hO commented on July 21, 2024 1

My requirement has already been resolved. I prefer not to add a .clang-format file to every cpp project, so I followed the link below to resolve it.
jose-elias-alvarez/null-ls.nvim#953

from nvim-config.

Alexis12119 avatar Alexis12119 commented on July 21, 2024

Hi, Good morning to you.

This is my function for the formatting logic.

https://github.com/Alexis12119/nvim-config/blob/main/lua/core/utils.lua#L19-L38

What it does is check if the null-ls is attached and has a formatting capability. If not, then the lsp attached that has formatting capability will be used for formatting.

This is the Format command.
https://github.com/Alexis12119/nvim-config/blob/main/lua/core/utils.lua#L98-L101

The format command is calling the format_code() function to format the file and I mapped the :Format command to <space>lf.

Also, I'm using .clang-format to customize how the clang-format will format my cpp file. You can use .clang-format to change the indent to 4.

Before formatting the file
Screenshot (66)

After formatting file through :Format or <leader>lf
Screenshot (67)

Hope it helps.

from nvim-config.

Alexis12119 avatar Alexis12119 commented on July 21, 2024

Is my explanation easy to understand? Because I feel like it's too long.

from nvim-config.

IC0hO avatar IC0hO commented on July 21, 2024

I see,I use clang-format to format my cpp file too but I still don't know how to change the indent to 4.Is it configured in null-ls? What is the relevant documentation like? I have installed clang_format by mason, and the command :NullLsInfo shows that clang_format is working correctly.
image

from nvim-config.

Alexis12119 avatar Alexis12119 commented on July 21, 2024

I created the .clang-fomat inside the directory of my cpp file. I changed the indent through .clang-format.

Screenshot (68)

from nvim-config.

IC0hO avatar IC0hO commented on July 21, 2024

There is a peculiar phenomenon where, after creating the .clang-format file, I am able to use 4-space indentation correctly. However, even after deleting the null-ls.lua file, it still retains the 4-space indentation. According to my understanding, at this point, it should be using the formatting of the LSP. Is the null-ls.lua file really having an effect?

from nvim-config.

Alexis12119 avatar Alexis12119 commented on July 21, 2024

I just noticed that clangd also uses .clang-format. It looks like I don't really need clang-format.

from nvim-config.

Alexis12119 avatar Alexis12119 commented on July 21, 2024

Look here:

Not same directory of .clang-format and cpp file.
Screenshot (70)

Same directory of .clang-format and cpp file.
Screenshot (71)

from nvim-config.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.