-
Notifications
You must be signed in to change notification settings - Fork 326
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
provideCompletionItems function is too big and requires splitting #896
Comments
Moved all image path completion code from within the if-else statement to a seperate function as part of refactoring of provideCompletionItems(). yzhang-gh#896 No functional changes, purely structural. Tested by adding a local images to a .md file and confirming image link completion is still functional
Just some thoughts for review. Major function splitThe following functions can be separated out from
But this is a fairly simple view, but this should probably be the initial pull request to keep things clean. After that the following should be considered. Discussion of functions
let addClosingParen = false;
if (/^([^\) ]+\s*|^\s*)\)/.test(lineTextAfter)) {
// try to detect if user wants to replace a link (i.e. matching closing paren and )
// Either: ... <CURSOR> something <whitespace> )
// or: ... <CURSOR> <whitespace> )
// or: ... <CURSOR> ) (endPosition assignment is a no-op for this case)
// in every case, we want to remove all characters after the cursor and before that first closing paren
endPosition = position.with({ character: + endPosition.character + lineTextAfter.indexOf(')') });
} else {
// If no closing paren is found, replace all trailing non-white-space chars and add a closing paren
// distance to first non-whitespace or EOL
const toReplace = (lineTextAfter.search(/(?<=^\S+)(\s|$)/))
endPosition = position.with({ character: + endPosition.character + toReplace });
if (!linkRefDefinition) {
addClosingParen = true;
}
}
|
My draft Overview
Notes
|
Nice ASCII art! Much more rip the whole thing down kind of approach, but i understand your desire for a cleaner overall design. How/when do you see the document model updating? Guessing it wouldn't update from scratch on each typed character but instead somehow update dynamically. Else it could get really slow on big files. Maybe you have a plan, or is this one of the tricky bits? I guess you need to keep track of the line/char position of the entry & exit point for each document element. And have that quickly searchable. |
I guess the document model extends outside the completion item scope and would be used as a basis for many other functions (for example you get syntax highlighting and checking almost for free). The only thing that you wouldn't get is "beautify" functionality for tables etc. But it would make scoping such things more straightforward. |
Thanks. @Lemmingh's design can be the long-term target which, as @gavbarnett said, goes somehow beyond the "completion" feature. Specific to this issue, what we should do now is
By doing this, we pave the way for replacing the regexp-based solution with the Engine/Providers one in the future. (We don't have to do all these in one go.) |
May still be worth defining the interfaces a bit here before we start. |
Have made a start at this in my local master branch https://github.com/gavbarnett/vscode-markdown/blob/master/src/completion.ts Just the simple step of splitting out the high level provider functions. Not sure I fully get how best to use the async cancel token (without changing too much else) but I've tried? Still got the Math bit to do something with. That's probably a good enough point to get to for the next Pull request. Following that I'll look at extracting common provider parts. |
You can open a draft PR so we can see the diff view and also may have some ideas 😉. |
Looks like you didn't refresh your working branch, so it's a bit hard to read the diff.
You can take the decoration manager as a reference. |
Doh! |
Think I've sorted that mess out now. Not sure how that happened. I thought I was up to date when I started, guess not. I did a diff on all the sections that it wasn't happy with and i'm convinced the code is the same. Now to look at the decorations manager and work out what to do with the cancel toekn. |
I usually do this git remote add upstream /url/to/original/repo # should already be okay, you can check with `git remote -v`
git fetch upstream
git checkout master
git merge upstream/master This will keep your own changes. Or you can use the GitHub UI (https://www.sitepoint.com/quick-tip-sync-your-fork-with-the-original-without-the-cli/) |
The problem is Three-way merge cannot update his branch. It needs detached checkout and then cherry pick. I'll take care of it. |
You can also learn cooperative cancellation model at |
Proposal
provideCompletionItems is big at almost 200 lines, It could be broken down into 5 main sub-function (one per if-else branch).
In doing that some smaller functions may become clear for making common (file-scraping for links & image links might being one possibly).
The math functions have been mostly broken out already (mathEnvCheck / this.mathCompletions)
The main benefits would be:
The text was updated successfully, but these errors were encountered: