mike-lischke / antlr4-c3

A grammar agnostic code completion engine for ANTLR4 based parsers
MIT License
396 stars 62 forks source link

#136 Remove FollowSet cache dependency on ignoredTokens #149

Closed vityaman closed 2 weeks ago

vityaman commented 1 month ago

There is a problem explained at https://github.com/mike-lischke/antlr4-c3/issues/136#issuecomment-2268664819 because of cache dependency on ignoredTokens value. I just removed the token filter in getFollowingTokens. This logic originally was added in "Initial commit" 7 years ago, so motivation is unclear. On the one hand, tests were not changed, so the behavior with which all are agreed is the same. On the other hand, now we can get some elements of ignoredTokens in followSet from candidates. It can be fixed by simply adding a check after followSet was received either from the cache or computation.

@mike-lischke, there are two questions:

  1. Do we want to filter tokens in follow set?

If yes, then I'll do changes and this test case will be OK:

core = CodeCompletionCore(X)
follow = core.collectCandidates(Y).tokens[Z] 
assert follow == [A, B, C]

core = CodeCompletionCore(X)
core.ignoredTokens.add(B)
follow = core.collectCandidates(Y).tokens[Z] 
assert follow == [A, C] // on 5eaad7b it returns [A, B, C]
  1. Do we want to propagate this change to all ports (TypeScript, Java)?
mike-lischke commented 3 weeks ago

I see no reason why to remove a useful feature. OK, it's not a big thing, but it's something that makes usage a bit easier. The problem described in #136 seems not to be related to this filtering of unwanted tokens.

vityaman commented 2 weeks ago

@mike-lischke, returned following tokens filtering based on ignoredTokens. I placed it right after processRule inside collectCandidates to avoid caching dependent results.

vityaman commented 2 weeks ago

@mike-lischke, if you are talking about this cache fix, I can make the same changes to Java and TypeScript versions of the library. Do we need it?

mike-lischke commented 2 weeks ago

No, no, that's not what I meant. I spoke about future changes in the TS version that would need to be tracked by the ports and the more the source code diverts, the harder it is to do that.