Skip to content

Commit

Permalink
feat: refactor atom.config values into the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Nov 11, 2020
1 parent 77afe39 commit a8b98b0
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions lib/paths-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ export default class PathsCache extends EventEmitter {
this._filePathsByProjectDirectory = new Map()
this._filePathsByDirectory = new Map()
this._fileWatchersByDirectory = new Map()

this.config = {
excludeVcsIgnoredPaths: atom.config.get('core.excludeVcsIgnoredPaths'),
ignoreSubmodules: atom.config.get('autocomplete-paths.ignoreSubmodules'),
shouldIgnoredNames: atom.config.get('autocomplete-paths.ignoredNames'),
ignoredNames: atom.config.get('core.ignoredNames'),
ignoredPatterns: atom.config.get('autocomplete-paths.ignoredPatterns'),
maxFileCount: atom.config.get('autocomplete-paths.maxFileCount')
}
}

/**
Expand All @@ -30,28 +39,25 @@ export default class PathsCache extends EventEmitter {
*/
_isPathIgnored (path) {
let ignored = false
if (atom.config.get('core.excludeVcsIgnoredPaths')) {
if (this.config.excludeVcsIgnoredPaths) {
this._repositories.forEach(repository => {
if (ignored) return
const ignoreSubmodules = atom.config.get('autocomplete-paths.ignoreSubmodules')
const isIgnoredSubmodule = ignoreSubmodules && repository.isSubmodule(path)
const isIgnoredSubmodule = this.config.ignoreSubmodules && repository.isSubmodule(path)
if (repository.isPathIgnored(path) || isIgnoredSubmodule) {
ignored = true
}
})
}

if (atom.config.get('autocomplete-paths.ignoredNames')) {
const ignoredNames = atom.config.get('core.ignoredNames')
ignoredNames.forEach(ignoredName => {
if (this.config.shouldIgnoredNames) {
this.config.ignoredName.forEach(ignoredName => {
if (ignored) return
ignored = ignored || minimatch(path, ignoredName, { matchBase: true, dot: true })
})
}

const ignoredPatterns = atom.config.get('autocomplete-paths.ignoredPatterns')
if (ignoredPatterns) {
ignoredPatterns.forEach(ignoredPattern => {
if (this.config.ignoredPatterns) {
this.config.ignoredPatterns.forEach(ignoredPattern => {
if (ignored) return
ignored = ignored || minimatch(path, ignoredPattern, { dot: true })
})
Expand Down Expand Up @@ -151,10 +157,9 @@ export default class PathsCache extends EventEmitter {
let filePathsArray = this._filePathsByProjectDirectory.get(projectDirectory.path) || []
const newPathsCount = filePathsArray.length + filePaths.length

const maxFileCount = atom.config.get('autocomplete-paths.maxFileCount')
if (newPathsCount > maxFileCount && !this._cancelled) {
if (newPathsCount > this.config.maxFileCount && !this._cancelled) {
atom.notifications.addError('autocomplete-paths', {
description: `Maximum file count of ${maxFileCount} has been exceeded. Path autocompletion will not work in this project.<br /><br /><a href="https://github.com/atom-community/autocomplete-paths/wiki/Troubleshooting#maximum-file-limit-exceeded">Click here to learn more.</a>`,
description: `Maximum file count of ${this.config.maxFileCount} has been exceeded. Path autocompletion will not work in this project.<br /><br /><a href="https://github.com/atom-community/autocomplete-paths/wiki/Troubleshooting#maximum-file-limit-exceeded">Click here to learn more.</a>`,
dismissable: true
})

Expand Down Expand Up @@ -374,11 +379,11 @@ export default class PathsCache extends EventEmitter {
_getIgnorePatterns(directoryPath) {
const patterns = [];

if (atom.config.get('autocomplete-paths.ignoredNames')) {
atom.config.get('core.ignoredNames').forEach(pattern => patterns.push(pattern));
if (this.config.shouldIgnoredNames) {
this.config.ignoredName.forEach(pattern => patterns.push(pattern));
}

if (atom.config.get('core.excludeVcsIgnoredPaths')) {
if (this.config.excludeVcsIgnoredPaths) {
try {
const gitIgnore = fs.readFileSync(directoryPath + '/.gitignore', 'utf-8');
gitIgnoreParser(gitIgnore).forEach(pattern => patterns.push(pattern));
Expand All @@ -388,9 +393,8 @@ export default class PathsCache extends EventEmitter {
}
}

const ignoredPatterns = atom.config.get('autocomplete-paths.ignoredPatterns');
if (ignoredPatterns) {
ignoredPatterns.forEach(pattern => patterns.push(pattern));
if (this.config.ignoredPatterns) {
this.config.ignoredPatterns.forEach(pattern => patterns.push(pattern));
}

return patterns;
Expand Down

0 comments on commit a8b98b0

Please sign in to comment.