Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit 1ed857d

Browse files
znckgrammarly-znck
andauthored
reposition alerts on typing & user configuration for hiding username in status bar (#155)
* reposition alerts on typing * add changeset Co-authored-by: Rahul Kadyan <[email protected]>
1 parent 09e889d commit 1ed857d

32 files changed

+506
-434
lines changed

.changeset/config.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
33
"changelog": "@changesets/cli/changelog",
44
"commit": false,
5-
"linked": [],
5+
"linked": [
6+
[
7+
"unofficial-grammarly-language-client",
8+
"unofficial-grammarly-language-server"
9+
]
10+
],
611
"access": "public",
712
"baseBranch": "main",
8-
"updateInternalDependencies": "patch",
9-
"ignore": [
10-
"grammarly-workspace"
11-
]
13+
"updateInternalDependencies": "patch"
1214
}

.changeset/itchy-steaks-bow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'unofficial-grammarly-language-server': minor
3+
---
4+
5+
Support dismiss alert feedback

.changeset/loud-dancers-run.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'grammarly': minor
3+
---
4+
5+
Show diagnostics in the correct position after accepting fixes

.changeset/six-dolphins-decide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'unofficial-grammarly-api': minor
3+
---
4+
5+
Add text transformation helper functions

extension/package.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,21 +325,30 @@
325325
"type": "boolean",
326326
"default": false,
327327
"description": "Hide premium alerts when fix is not available"
328+
},
329+
"grammarly.showDeletedTextInQuickFix": {
330+
"type": "boolean",
331+
"default": true,
332+
"description": "Show replaced text in quick-fix option."
333+
},
334+
"grammarly.showUsernameInStatusBar": {
335+
"type": "boolean",
336+
"default": true,
337+
"description": "Show signed in user in status bar."
328338
}
329339
}
330340
},
331341
"commands": [
332342
{
333343
"command": "grammarly.check",
334344
"title": "Check grammar errors",
335-
"category": "Grammarly",
336-
"enablement": "grammarly:isSupported"
345+
"category": "Grammarly"
337346
},
338347
{
339348
"command": "grammarly.stop",
340349
"title": "Stop checking grammar errors",
341350
"category": "Grammarly",
342-
"enablement": "grammarly:isSupported && grammarly:isActive"
351+
"enablement": "grammarly:isActive"
343352
},
344353
{
345354
"command": "grammarly.login",
@@ -357,7 +366,7 @@
357366
"command": "grammarly.setGoals",
358367
"title": "Set document goals",
359368
"category": "Grammarly",
360-
"enablement": "grammarly:isSupported && grammarly:isActive"
369+
"enablement": "grammarly:isActive"
361370
}
362371
]
363372
},

extension/src/client/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export class GrammarlyClient extends GrammarlyLanguageClient implements Register
1616
return null
1717
},
1818
loadToken: async () => {
19-
console.log('Get token...')
2019
if (process.env.EXTENSION_TEST_MODE) return null
2120

2221
return await this.auth.getCookie()

extension/src/commands/ServerCallbackCommand.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Logger } from '../utils/Logger'
88
export class ServerCallbackCommand implements Registerable {
99
private LOGGER = new Logger(ServerCallbackCommand.name)
1010

11-
constructor(private readonly client: GrammarlyClient) {}
11+
constructor (private readonly client: GrammarlyClient) { }
1212

1313
register() {
1414
this.LOGGER.trace('Registering grammarly.callback command')
@@ -17,7 +17,6 @@ export class ServerCallbackCommand implements Registerable {
1717
}
1818

1919
private async execute(options: { method: string; params: any }) {
20-
this.LOGGER.trace('Executed with', options)
2120
if (!this.client.isReady()) {
2221
await this.client.onReady()
2322
}

extension/src/controllers/StatusBarController.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { ref } from '@vue/reactivity'
22
import { injectable } from 'inversify'
33
import { GrammarlyLanguageServer } from 'unofficial-grammarly-language-server'
4-
import { Disposable, StatusBarAlignment, StatusBarItem, TextEditor, ThemeColor, window } from 'vscode'
4+
import { Disposable, StatusBarAlignment, StatusBarItem, TextEditor, ThemeColor, Uri, window, workspace } from 'vscode'
55
import { GrammarlyClient } from '../client'
66
import { Registerable } from '../interfaces'
7+
import { DEFAULT, GrammarlySettings } from '../settings'
78
import { asText, calculateTime, capitalize, choose, formatLines } from '../utils/string'
89
import { watchEffect } from '../utils/watch'
910

@@ -39,6 +40,11 @@ export class StatusBarController implements Registerable {
3940
this.statusBar,
4041
this.goalsBar,
4142
window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor.bind(this)),
43+
workspace.onDidChangeConfiguration(event => {
44+
if (event.affectsConfiguration('grammarly')) {
45+
this.update()
46+
}
47+
}),
4248
{
4349
dispose: watchEffect(() => {
4450
this.update()
@@ -47,19 +53,26 @@ export class StatusBarController implements Registerable {
4753
)
4854
}
4955

56+
private getSettings(): GrammarlySettings {
57+
const uri = this.document.value != null ? Uri.parse(this.document.value.uri) : undefined
58+
const config = workspace.getConfiguration(undefined, uri)
59+
60+
return config.get<GrammarlySettings>('grammarly') ?? DEFAULT
61+
}
62+
5063
private update() {
51-
console.log('Calling watch effect...')
5264
const state = this.state.value
5365
const document = this.document.value
5466

5567
if (state != null && 'status' in state) {
5668
const prefix = state.emotions.length ? state.emotions[0].emoji : ``
5769

70+
const settings = this.getSettings()
5871
this.statusBar.command = 'grammarly.stop'
59-
this.statusBar.text = `${state.status === 'CHECKING' ? '$(loading~spin)' : '$(debug-disconnect)'} ${state.user.username}`
72+
this.statusBar.text = `${state.status === 'CHECKING' ? '$(loading~spin)' : '$(debug-disconnect)'}${settings.showUsernameInStatusBar ? ` ${state.user.username}` : ''}`
6073

6174
this.statusBar.tooltip = `${state.status === 'IDLE' ? 'Grammarly is checking for grammar errors.\n\n' : ''
62-
}Click to disconnect Grammarly.`
75+
}Connected as ${state.user.username}, click to disconnect.`
6376

6477
this.goalsBar.command = 'grammarly.setGoals'
6578
this.goalsBar.text = `${prefix} ${state.score > 0 ? `${state.score} overall score` : ''}`

extension/src/settings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export interface GrammarlySettings extends DocumentContext {
2121
}>
2222

2323
debug: boolean
24+
showUsernameInStatusBar: boolean
25+
showDeletedTextInQuickFix: boolean
2426
showExplanation: boolean
2527
showExamples: boolean
2628
hideUnavailablePremiumAlerts: boolean
@@ -72,6 +74,8 @@ export const DEFAULT: GrammarlySettings = {
7274

7375
/** Internal */
7476
debug: false,
77+
showUsernameInStatusBar: true,
78+
showDeletedTextInQuickFix: true,
7579
showExplanation: true,
7680
showExamples: false,
7781
hideUnavailablePremiumAlerts: false,

extension/src/utils/Logger.ts

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
import { inspect } from 'util'
2-
import { isError, isString } from './is'
3-
4-
export enum LoggerLevel {
5-
TRACE = 'TRACE',
6-
DEBUG = 'DEBUG',
7-
INFO = 'INFO',
8-
WARN = 'WARN',
9-
ERROR = 'ERROR',
10-
NONE = 'NONE',
2+
3+
export const enum LoggerLevel {
4+
TRACE,
5+
DEBUG,
6+
INFO,
7+
WARN,
8+
ERROR,
9+
NONE,
10+
}
11+
12+
const displayLevel = {
13+
[LoggerLevel.TRACE]: 'TRACE',
14+
[LoggerLevel.DEBUG]: 'DEBUG',
15+
[LoggerLevel.INFO]: 'INFO',
16+
[LoggerLevel.WARN]: 'WARN',
17+
[LoggerLevel.ERROR]: 'ERROR',
18+
[LoggerLevel.NONE]: 'NONE',
19+
}
20+
21+
function isString(value: any): value is string {
22+
return typeof value === 'string'
23+
}
24+
25+
function isError(value: any): value is Error {
26+
return value instanceof Error
1127
}
1228

1329
export class Logger {
14-
static Level = LoggerLevel
1530
static options = {
1631
enabled: new Set(['*']),
17-
level: LoggerLevel.TRACE,
32+
level: LoggerLevel.DEBUG,
1833
}
1934

20-
constructor(public readonly name: string, public readonly defaultContext: string = '') {}
35+
constructor (public readonly name: string, public readonly defaultContext: string = '') { }
2136

2237
trace(msg: string, ...args: any[]): void
2338
trace(context: string, msg: string, ...args: any[]): void
@@ -28,37 +43,40 @@ export class Logger {
2843
debug(msg: string, ...args: any[]): void
2944
debug(context: string, msg: string, ...args: any[]): void
3045
debug(...args: any[]) {
31-
this.write(LoggerLevel.TRACE, args)
46+
this.write(LoggerLevel.DEBUG, args)
3247
}
3348

3449
info(msg: string, ...args: any[]): void
3550
info(context: string, msg: string, ...args: any[]): void
3651
info(...args: any[]) {
37-
this.write(LoggerLevel.TRACE, args)
52+
this.write(LoggerLevel.INFO, args)
3853
}
3954

4055
warn(msg: string, ...args: any[]): void
4156
warn(context: string, msg: string, ...args: any[]): void
4257
warn(...args: any[]) {
43-
this.write(LoggerLevel.TRACE, args)
58+
this.write(LoggerLevel.WARN, args)
4459
}
4560

4661
error(msg: string, ...args: any[]): void
4762
error(msg: Error, ...args: any[]): void
4863
error(context: string, msg: string, ...args: any[]): void
4964
error(context: string, msg: Error, ...args: any[]): void
5065
error(...args: any[]) {
51-
this.write(LoggerLevel.TRACE, args)
66+
this.write(LoggerLevel.ERROR, args)
5267
}
5368

5469
private write(level: LoggerLevel, args: any[]) {
55-
if (level >= Logger.options.level && (Logger.options.enabled.has('*') || Logger.options.enabled.has(this.name))) {
70+
if (
71+
level >= Logger.options.level &&
72+
(Logger.options.enabled.has('*') || Logger.options.enabled.has(this.name))
73+
) {
5674
const context =
5775
args.length >= 2 && isString(args[0]) && (isString(args[1]) || isError(args[1]))
5876
? args.shift()
5977
: this.defaultContext
6078

61-
const message = `${Date.now()} ${level} [${this.name}]${context ? ' (' + context + ')' : ''} ${this.inspect(
79+
const message = `${Date.now()} ${displayLevel[level]} [${this.name}]${context ? ' (' + context + ')' : ''} ${this.inspect(
6280
args,
6381
)}`
6482

@@ -80,3 +98,5 @@ export class Logger {
8098
return args.map((arg) => (typeof arg === 'object' && arg ? inspect(arg, true, null) : arg)).join(' ')
8199
}
82100
}
101+
102+
export class DevLogger extends Logger { }

0 commit comments

Comments
 (0)