Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[bugfix] Correct the content shown in status-bar #202

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
jdneo merged 2 commits into master from cs/statusbar
Mar 13, 2019
Merged
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
15 changes: 14 additions & 1 deletion src/leetCodeManager.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LeetCodeManager extends EventEmitter {
public async getLoginStatus(): Promise<void> {
try {
const result: string = await leetCodeExecutor.getUserInfo();
this.currentUser = result.slice("You are now login as".length).trim();
this.currentUser = this.tryParseUserName(result);
this.userStatus = UserStatus.SignedIn;
} catch (error) {
this.currentUser = undefined;
Expand Down Expand Up @@ -117,6 +117,19 @@ class LeetCodeManager extends EventEmitter {
public getUser(): string | undefined {
return this.currentUser;
}

private tryParseUserName(output: string): string {
const lines: string[] = output.trim().split(/\r?\n/);
if (lines.length === 3) {
const reg: RegExp = /^\s*.{1}\s*(.+)\s*https:\/\/leetcode/;
Copy link
Contributor

Choose a reason for hiding this comment

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

The regex executing on

×ばつ vigilans https://leetcode-cn.com'">
' ×ばつ vigilans https://leetcode-cn.com'

will return

'vigilans '

Append ? to .+ to prevent greedy match could solve the problem.

Besides, is there any difference between .{1} and .?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

const match: RegExpMatchArray | null = lines[2].match(reg);
if (match && match.length === 2) {
return match[1].trim();
}
}

return "Unknown";
}
}

export const leetCodeManager: LeetCodeManager = new LeetCodeManager();

AltStyle によって変換されたページ (->オリジナル) /