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

🏗 Split CompletionItemProvider into smaller modules #905

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

gavbarnett
Copy link
Contributor

Stepping stone to resolve #896

No functional changes, purely structural.

@gavbarnett
Copy link
Contributor Author

gavbarnett commented Feb 18, 2021

Some work still required before merge I think:

  • review cancellation token use (sorry I still don't understand this)
  • name the regex used in the if-else as variables for clarity

@Lemmingh Lemmingh marked this pull request as draft February 19, 2021 03:44
@Lemmingh Lemmingh self-assigned this Feb 19, 2021
@Lemmingh Lemmingh added Area: Auto completion Code completion and suggestion, aka IntelliSense. Area: Meta Pertaining to build system, test system, infrastructure, code health, and the project itself. labels Feb 19, 2021
gavbarnett and others added 7 commits February 20, 2021 00:42
Code is just moved from the the main completion function. No functional changes

Function is async and has a Cancellation token, though the later could likely be better made use of.

I've  duplicated the lineTextBefore variable within the function rather than passing it in. This is less efficient just now but I think it will be cleaner once all completion functions are separated out. Eventually I don't think it will be needed within the function at all.
code is just moved from main completion function.

No functional changes.
Just moved code from main completion function.

No functional changes.
lineAfterTest variable also moved in to this function as it is the only place it is used.
Code just moved from main function

No functional changes.
No functional changes, just tidying code.
required renaming of previous `mathCompletion` variable to `mathCompletionItems`

Just moving code from main to new function. No functional change.

Consider moving `mathCompletionItems` into new function in future
@Lemmingh Lemmingh changed the base branch from master to master-2 February 19, 2021 17:19
@Lemmingh Lemmingh changed the base branch from master-2 to master February 19, 2021 17:19
@Lemmingh
Copy link
Collaborator

This repo enforces squash merge and linear history for mainline now.

So, after your PR got merged, you need to discard the old work branch and create a new one, or perform equivalent operations. There are many approaches.

Thanks.

Naming needs further discussion.
@gavbarnett
Copy link
Contributor Author

I was wondering about the LaTeX/KaTeX stuff. Should it be treated differently than the other completion parts. I mean should it be treated like it's an extension. In that way we plan for other CM "extensions" in future.

Maybe that's more for discussion when we get to the longer term design.

Matches is type string array,

The line `matches = lineTextBefore.match(/\\+$/);` seems to be old code and is not doing anything of use. It is repeated a few lines further down in the if statement for maths completion.
Using named key-value pair for code clarity.
Previous capture relied on counting number of backslashes after matching a regex and performing modular arithmetic to check for an odd number.

This commit is to change the latexCmd regex to a single line which says:
`/(^|[^\\])([\\]{2})*\\$/`

```
IF ( ( (on new line) OR (following a non-backslash char) )
   AND (0 or more pairs of backslashes)
   AND a single backslash )
THEN there are an odd number of backslashes.
```

The benefit of this is to better align with the other regex's used in the if-else statement. also removes need for `matches` variable.
@gavbarnett
Copy link
Contributor Author

gavbarnett commented Feb 24, 2021

Please do some extra testing on 43ab0ea which updated the latex "ends in odd number of backslashes" if-statement to a single line regex and removed the need for the modulo operation.

Latex is not something I use really, but I think my one-liner works to capture what is required. /(^|[^\\])([\\]{2})*\\$/
Please try to break it 👍

Also feel free to do some renaming as you see fit.

@yzhang-gh
Copy link
Owner

Thanks @gavbarnett. Looks we are in the right direction 👍 (although I didn't test it). And sorry that I only have limited time for this extension in the following weeks.

@Lemmingh Lemmingh added this to the v3.6.0 milestone Jun 20, 2021
@Lemmingh Lemmingh changed the title Splitting provideCompletionItems into smaller provider functions 🏗 Split CompletionItemProvider into smaller modules Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Auto completion Code completion and suggestion, aka IntelliSense. Area: Meta Pertaining to build system, test system, infrastructure, code health, and the project itself.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

provideCompletionItems function is too big and requires splitting
3 participants