Skip to content

fix: CodeLens position #426

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

Merged
merged 3 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,6 @@
"markdown-it": "^8.4.2",
"require-from-string": "^2.0.2",
"unescape-js": "^1.1.1",
"vsc-leetcode-cli": "2.6.10"
"vsc-leetcode-cli": "2.6.11"
}
}
15 changes: 4 additions & 11 deletions src/codelens/CustomCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,16 @@ export class CustomCodeLensProvider implements vscode.CodeLensProvider {
return;
}

const fileName: string = document.fileName.trim();
const workspaceFolder: string = vscode.workspace.getConfiguration("leetcode").get("workspaceFolder", "");

if (fileName.indexOf(workspaceFolder) === -1) {
return undefined;
}

const content: string = document.getText();
const matchResult: RegExpMatchArray | null = content.match(/@lc app=.* id=.* lang=.*/);
if (!matchResult) {
return undefined;
}

let codeLensLine: number = content.length - 1;

for (let i: number = 0; i < content.length; ++i) {
if (content[i].indexOf("@lc code=end") >= 0) {
let codeLensLine: number = document.lineCount - 1;
for (let i: number = document.lineCount - 1; i >= 0; i--) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that the algorithm of the @lc code=end line is different from the algorithm in leetcode-cli.

Copy link
Member

Choose a reason for hiding this comment

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

Any concern for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there are two lines which contain @lc code=end, We will get inconsistent behavior.
But it is rare, so we don't have to deal with it.

Copy link
Member

@jdneo jdneo Sep 30, 2019

Choose a reason for hiding this comment

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

Since we have no context information, so this is the case that we cannot deal with no matter what algorithm we take. So let's just keep it as it is.

Thank you for the feedback anyway.

const lineContent: string = document.lineAt(i).text;
if (lineContent.indexOf("@lc code=end") >= 0) {
codeLensLine = i;
break;
}
Expand Down