Skip to content

Commit

Permalink
perf: less clear cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjiaxuan committed Feb 13, 2023
1 parent 15b80d6 commit 3a20d80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,16 @@ export async function activate(context: ExtensionContext) {
window.onDidChangeActiveTextEditor(() => commands.executeCommand('eslint-disable.disableIT', true))
workspace.onDidChangeTextDocument(event => {
const fileName = event.document.fileName
if (lintingCache.has(fileName)) {
// PERF: It would be trigger by `eslint-disable` directive comments inserted which is not expected.

if (!event.contentChanges.length) {
return
}

const isOnlyESLintDisableText = event.contentChanges.every(({ text }) => {
const trimText = text.trim()
return trimText.startsWith('// eslint-disable-next-line ') || trimText.startsWith('// eslint-disable ')
})
if (!isOnlyESLintDisableText && lintingCache.has(fileName)) {
lintingCache.delete(fileName)
log(`${ fileName } - Clear linting cache.`)
}
Expand Down Expand Up @@ -125,7 +133,7 @@ const disposes = [
} else {
const parseFileName = path.parse(fileName).base
log(`${ fileName } - Linting cache found.`)
showStatusBarItem(`Linting cache found for ${ parseFileName }.`)
showStatusBarItem(`Linting cache found at ${ parseFileName }.`)
}


Expand Down Expand Up @@ -161,13 +169,15 @@ const disposes = [
new SnippetString(`// eslint-disable-next-line \${1|${ lineRuleIdsMap![selection.start.line + 1].join('\\, ') }|}\n`),
new Position(selection.start.line, insertIndex),
)
delete lineRuleIdsMap![selection.start.line + 1]
} else {
// Wrap lines. Press `ctrl+d `to edit rules at between lines.

const ruleIDSet = new Set<string>()
for (const line in lineRuleIdsMap) {
if (selection.start.line + 1 <= +line && +line <= selection.end.line + 1) {
lineRuleIdsMap[+line].forEach(item => ruleIDSet.add(item))
delete lineRuleIdsMap[+line]
}
}

Expand Down Expand Up @@ -197,6 +207,7 @@ const disposes = [
],
},
})
lintingCache.clear()
log('Reloading finished.')
showStatusBarItem('$(check) Reloading finished.')
}),
Expand Down
2 changes: 1 addition & 1 deletion src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export default (
...informationMessage: string[]
) => {
channel.appendLine(`[${ getNowFormat() }] - ${ message }`)
showInformationMessage && window.showInformationMessage(message, ...informationMessage)
showInformationMessage && void window.showInformationMessage(message, ...informationMessage)
}

0 comments on commit 3a20d80

Please sign in to comment.