Git Product home page Git Product logo

Comments (6)

sam-mccall avatar sam-mccall commented on June 8, 2024

Ah, this one fell through the cracks. It's important that the #define is part of the preamble (the initial block of preprocessor directives). Add int x; to the top of the file and everything works again.

The problem is we assumed that "in the preamble" was the same thing as "not in the main file", and so we don't index symbols in the main file. This assumption is true for decls, but not for macros.

from clangd.

lh123 avatar lh123 commented on June 8, 2024

Ah, this one fell through the cracks. It's important that the #define is part of the preamble (the initial block of preprocessor directives). Add int x; to the top of the file and everything works again.

Yes, add int x; to the top of the file and everything is back to normal. But the macro's document still doesn't show in codecomplete.

Document does not display for macros

image
image

from clangd.

sam-mccall avatar sam-mccall commented on June 8, 2024

This is a bit hairy:

  • we see the macros when indexing the preamble, but we don't actually want the macros in the index: that would make them complete while in other files.
  • we don't see the macros when indexing the main file, because the lexer starts after the preamble region

I see two main options:

  • when building the preamble, record the macros and store them alongside the preamble
  • when code completing, preprocess the preamble region in single-file mode to get the macros
    In either case, we then need to overlay the result onto the index.
    The first option is more correct - single-file mode doesn't follow includes and therefore isn't accurate. But the first option probably involves some layering violations or code duplication (if the preamble-building code needs to run SymbolCollector), and certainly involves more plumbing.

Macro doc I'm not sure about - I forget exactly how we extract doc comments, will have a look into that if it persists after the main issue is fixed.

from clangd.

sam-mccall avatar sam-mccall commented on June 8, 2024

On further reflection, clearly the preamble contains the macros, the question is whether we can get them out efficiently.

ASTReader::ReadDefinedMacros is responsible for decoding.
The preprocessor block appears to be very small: it's 0.8%, or roughly 300kB in a 45M LLVM preamble.
As far as I can see, it contains macro identifiers (PP_MACRO_FUNCTION_LIKE, PP_MACRO_OBJECT_LIKE), macro definition sites (PP_MACRO_DIRECTIVE_HISTORY), and a little bit of stuff we don't need. So far so good.

Unfortunately it looks like the path from identifier -> definition site goes through the name lookup table that's used for all identifiers, and deserializing anything that matches! I'll need to measure if this is expensive.

from clangd.

sam-mccall avatar sam-mccall commented on June 8, 2024

Finally have an approach here that seems okayish...
https://reviews.llvm.org/D60937

from clangd.

sam-mccall avatar sam-mccall commented on June 8, 2024

Fixed in r359799.
Thanks for reporting!

from clangd.

Related Issues (20)

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.