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

Fix #152510 #152955

Closed
wants to merge 16 commits into from
Closed

Fix #152510 #152955

wants to merge 16 commits into from

Conversation

Harry-Hopkinson
Copy link

This PR fixes #152510, adds path suggestions for angled brackets in markdown.

@Harry-Hopkinson Harry-Hopkinson marked this pull request as ready for review June 23, 2022 17:04
Copy link
Collaborator

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add some tests for this. I'm think there are some bugs with the proposed change but tests will help track these down

@@ -171,4 +171,14 @@ suite('Markdown path completion provider', () => {

assert.ok(completions.some(x => x.insertText === 'file.md'), 'Has file from space');
});

test('Should complete path for angled brackets', async () => {
Copy link
Collaborator

@mjbvz mjbvz Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add tests for:

  • Incomplete links: [](<${CURSOR}
  • Links that appear inside text on the line: text [](<${CURSOR}>) more text
  • Links with titles: [](<${CURSOR}> "title")
  • Any other edge cases

I'm pretty sure the code will break for all of those today

@@ -181,6 +181,24 @@ export class MdVsCodePathCompletionProvider implements vscode.CompletionItemProv
};
}

const angleBrackets = /^\s*\[(.*?)\]\(\s*<(.*?)>\s*$/;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this can't just be part of the linePrefixText regex? It's the same prefix, just with a < at the start of the link

return undefined;
}

const suffix = lineSuffixText.match(/^[^\)\s]*/);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When completions for <> paths are accepted, they should not encode the path components. Make sure to add a test for completions with a space in the name to check that encoding doesn't happen

@@ -181,6 +181,24 @@ export class MdVsCodePathCompletionProvider implements vscode.CompletionItemProv
};
}

const angleBrackets = /^\s*\[(.*?)\]\(\s*<(.*?)>\s*$/;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regular expression should match up the cursor inside the link. Right now it tries to match the entire link (Notice how the normal link regex above doesn't require ^\s*) at the start

@@ -181,6 +181,23 @@ export class MdVsCodePathCompletionProvider implements vscode.CompletionItemProv
};
}

const angleBracketsMatch = linePrefixText.match(this.referenceLinkStartPattern);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This match was already run so we should just re-use the result from above

});

test('Path component should not be encoded with <>', async () => {
const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually test that encoding isn't happening. For that you need to check the completions for a path with spaces in it. See Should escape spaces in path names as an example

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also isn't testing the new behavior. This should test that completions inside <> links don't encode paths with spaces in them

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but this is still incorrect (and I believe will also fail as written at the moment). Here's what the test needs to be:

For any of the cases:

[](<./CURSOR
or 
[](</CURSOR
or 
[](<CURSOR

Completions for paths with spaces in their name use an insert text that does not %20 encode the spaces:

assert.ok(completions.some(x => x.insertText === 'sub with space/'), 'Has sub folder completion');

@mjbvz
Copy link
Collaborator

mjbvz commented Jun 24, 2022

Looks like pathCompletions.ts needs to be formatted. Also make sure to run the unit tests since once of them was failing previously

@mjbvz
Copy link
Collaborator

mjbvz commented Jun 24, 2022

Sorry but I've merged #153158 which fixes this. I felt getting this PR into good shape was a mergable state would require a lot more back and forth

@mjbvz mjbvz closed this Jun 24, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Aug 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No path suggestions inside of angle bracet markdown link
2 participants