Skip to content

Commit

Permalink
feat: add a number of detected hardcoded strings in tree view, close #…
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jul 28, 2021
1 parent 301152f commit a83f00c
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
],
"i18n-ally.enabledFrameworks": [
"vscode",
"vue"
"vue",
"general"
],
"i18n-ally.theme.annotationMissingBorder": "#d37070",
"i18n-ally.theme.annotationMissing": "#d37070",
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
"review.unknown_user": "Unknown",
"view.current_file": "Current file",
"view.current_file_hard_strings": "Hard-coded strings [beta]",
"view.current_file_hard_strings_expand_to_detect": "(Expand to detect)",
"view.current_file_hard_strings_not_supported": "\"{0}\" is not supported yet",
"view.current_file_keys_in_use": "Keys in use",
"view.current_file_keys_not_found": "Keys not found",
Expand Down
4 changes: 2 additions & 2 deletions src/editor/reviewComments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { comments, CommentController, TextDocument, CancellationToken, Range, Disposable, commands, CommentReply, CommentAuthorInformation, Uri, Comment, MarkdownString, CommentMode, CommentThread } from 'vscode'
import { comments, CommentController, TextDocument, Range, Disposable, commands, CommentReply, CommentAuthorInformation, Uri, Comment, MarkdownString, CommentMode, CommentThread } from 'vscode'
import { EXT_REVIEW_ID } from '../meta'
import { getAvatarFromEmail } from '../utils/shared'
import { ExtensionModule } from '~/modules'
Expand Down Expand Up @@ -141,7 +141,7 @@ class ReviewCommentProvider implements Disposable {
return Global.enabledParsers.filter(p => p.annotationSupported)
}

async provideCommentingRanges(document: TextDocument, token: CancellationToken): Promise<Range[]> {
async provideCommentingRanges(document: TextDocument): Promise<Range[]> {
const filepath = document.uri.fsPath

if (this._threads[filepath]) {
Expand Down
2 changes: 1 addition & 1 deletion src/editor/statusbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ExtensionModule } from '~/modules'
import { Config, Global, CurrentFile } from '~/core'
import i18n from '~/i18n'

const statusbar: ExtensionModule = (ctx) => {
const statusbar: ExtensionModule = () => {
const disposables: Disposable[] = []
const priority = -1000
const bar1 = window.createStatusBarItem(StatusBarAlignment.Right, priority + 1)
Expand Down
6 changes: 3 additions & 3 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-ignore
export const isProd: boolean = process.env.NODE_ENV === 'production'
export const isDev: boolean = !isProd
export const isProd: boolean = process.env.NODE_ENV === 'production'
export const isDev = !isProd
// @ts-ignore
export const isTest: boolean = process.env.NODE_ENV === 'test'
export const isTest: boolean = process.env.NODE_ENV === 'test'
1 change: 1 addition & 0 deletions src/extraction/rules/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum ExtractionScore {
export abstract class ExtractionRule {
abstract name: string

// eslint-disable-next-line @typescript-eslint/no-unused-vars
shouldExtract(str: string): ExtractionScore | void {
return ExtractionScore.None
}
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/json5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Json5Parser extends Parser {
return JSON5.parse(text)
}

async dump(object: object, sort: boolean) {
async dump(object: object) {
return JSON5.stringify(object, {
space: this.options.tab === '\t' ? this.options.tab : this.options.indent,
})
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class PhpParser extends Parser {
return parser.parse(text)
}

async dump(object: object, sort: boolean) {
async dump() {
return ''
}
}
1 change: 1 addition & 0 deletions src/tagSystems/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export abstract class BaseTagSystem {
return bcp47
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
toFlagname(locale: string): string | undefined {
return undefined
}
Expand Down
2 changes: 1 addition & 1 deletion src/tagSystems/none.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BCP47 } from './bcp47'
// but do nothing on normalization
export class NoneTagSystem extends BCP47 {
// no convertsion
normalize(locale?: string, fallback = 'en', strict = false) {
normalize(locale?: string, fallback = 'en') {
return locale || fallback
}
}
21 changes: 15 additions & 6 deletions src/views/items/CurrentFileExtractionItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,34 @@ export class CurrentFileExtractionItem extends BaseTreeItem {
else {
this.collapsibleState = TreeItemCollapsibleState.None
}
this.updateDescription()
}

getLabel() {
return i18n.t('view.current_file_hard_strings')
}

updateDescription() {
// @ts-expect-error
get description() {
if (this.collapsibleState === TreeItemCollapsibleState.None) {
this.iconPath = this.getIcon('symbol-string-gray')
this.description = i18n.t('view.current_file_hard_strings_not_supported', this.langId)
return i18n.t('view.current_file_hard_strings_not_supported', this.langId)
}
else {
this.iconPath = this.getIcon('symbol-string')
const length = CurrentFile.hardStrings?.length
this.description = length == null ? '' : length.toString()
if (this.collapsibleState === TreeItemCollapsibleState.Collapsed && !length)
return i18n.t('view.current_file_hard_strings_expand_to_detect')
else
return length == null ? '' : length.toString()
}
}

// @ts-expect-error
get iconPath() {
if (this.collapsibleState === TreeItemCollapsibleState.None)
return this.getIcon('symbol-string-gray')
else
return this.getIcon('symbol-string')
}

async getChildren() {
if (this.collapsibleState === TreeItemCollapsibleState.None)
return []
Expand Down
1 change: 1 addition & 0 deletions src/views/providers/CurrentFileLocalesTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class CurrentFileLocalesTreeProvider implements TreeDataProvider<BaseTree
this.loadCurrentDocument()

CurrentFile.onInvalidate(() => this.loadCurrentDocument())
CurrentFile.onHardStringDetected(() => this.refresh())
}

getTreeItem(element: BaseTreeItem): TreeItem {
Expand Down
4 changes: 2 additions & 2 deletions src/views/providers/HelpFeedbackProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TreeItem, ExtensionContext, TreeDataProvider, Command } from 'vscode'
import { Commands } from '../../commands'
import Links from '../../links'
import { FeedbackItem } from '../items/FeedbackItem'
import Links from '~/links'
import { Commands } from '~/commands'
import i18n from '~/i18n'

export interface FeedbackItemDefintion {
Expand Down
2 changes: 1 addition & 1 deletion src/views/providers/LocalesTreeProvider.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { TreeItem, ExtensionContext, TreeDataProvider, EventEmitter, Event } from 'vscode'
import { sortBy, throttle } from 'lodash'
import { resolveFlattenRootKeypath } from '~/utils'
import { LocaleTreeItem } from '../items/LocaleTreeItem'
import { EditorPanel } from '../../webview/panel'
import { THROTTLE_DELAY } from '../../meta'
import { resolveFlattenRootKeypath } from '~/utils'
import { Node, Loader, CurrentFile, LocaleTree, LocaleNode } from '~/core'

export class LocalesTreeProvider implements TreeDataProvider<LocaleTreeItem> {
Expand Down

0 comments on commit a83f00c

Please sign in to comment.