Skip to content
This repository was archived by the owner on May 19, 2023. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
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
78 changes: 5 additions & 73 deletions lib/fuzzy-finder-view.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const {Point, CompositeDisposable} = require('atom')
const {renderExperimentPrompt, shouldShowPrompt} = require('./experiment-prompt')
const fs = require('fs-plus')
const fuzzaldrin = require('fuzzaldrin')
const fuzzaldrinPlus = require('fuzzaldrin-plus')
const NativeFuzzy = require('@atom/fuzzy-native')
const SCORING_SYSTEMS = require('./scoring-systems')

const path = require('path')
Expand Down Expand Up @@ -85,25 +83,7 @@ module.exports = class FuzzyFinderView {
elementForItem: ({filePath, label, ownerGitHubUsername}) => {
const filterQuery = this.selectListView.getFilterQuery()

let matches

switch (this.scoringSystem) {
case SCORING_SYSTEMS.STANDARD:
matches = fuzzaldrin.match(label, filterQuery)
break
case SCORING_SYSTEMS.FAST:
this.nativeFuzzyForResults.setCandidates([0], [label])
const items = this.nativeFuzzyForResults.match(
filterQuery,
{maxResults: 1, recordMatchIndexes: true}
)
matches = items.length ? items[0].matchIndexes : []
break
default:
matches = fuzzaldrinPlus.match(label, filterQuery)
break
}

let matches = fuzzaldrinPlus.match(label, filterQuery)
const repository = repositoryForPath(filePath)

return new FuzzyFinderItem({
Expand Down Expand Up @@ -143,34 +123,8 @@ module.exports = class FuzzyFinderView {
}
})

this.subscriptions = new CompositeDisposable()
this.subscriptions.add(
atom.config.observe('fuzzy-finder.scoringSystem', (newValue) => {
this.scoringSystem = newValue

if (this.scoringSystem === SCORING_SYSTEMS.STANDARD) {
this.selectListView.update({filter: null})
} else if (this.scoringSystem === SCORING_SYSTEMS.FAST) {
if (!this.nativeFuzzy) {
this.nativeFuzzy = new NativeFuzzy.Matcher(
indexArray(this.items.length),
this.items.map(el => el.label)
)

// We need a separate instance of the fuzzy finder to calculate the
// matched paths only for the returned results. This speeds up considerably
// the filtering of items.
this.nativeFuzzyForResults = new NativeFuzzy.Matcher([], [])
}

this.selectListView.update({ filter: this.filterFn })
} else {
this.selectListView.update({ filter: this.filterFn })
}

this.updateExperimentPrompt()
})
)
this.selectListView.update({ filter: this.filterFn })
this.updateExperimentPrompt()
}

get element () {
Expand All @@ -182,11 +136,6 @@ module.exports = class FuzzyFinderView {
this.panel.destroy()
}

if (this.subscriptions) {
this.subscriptions.dispose()
this.subscriptions = null
}

return this.selectListView.destroy()
}

Expand Down Expand Up @@ -332,14 +281,6 @@ module.exports = class FuzzyFinderView {
setItems (items) {
this.items = items

if (this.scoringSystem === SCORING_SYSTEMS.FAST) {
// Beware: this operation is quite slow for large projects!
this.nativeFuzzy.setCandidates(
indexArray(this.items.length),
this.items.map(item => item.label)
)
}

if (this.isQueryALineJump()) {
this.selectListView.update({
items: [],
Expand Down Expand Up @@ -403,19 +344,10 @@ module.exports = class FuzzyFinderView {
return items
}

let results
const startTime = performance.now()

if (this.scoringSystem === SCORING_SYSTEMS.FAST) {
results = this.nativeFuzzy.match(query, {maxResults: MAX_RESULTS})
.map(({id}) => this.items[id])
} else {
results = fuzzaldrinPlus.filter(items, query, {key: 'label'})
}

let results = fuzzaldrinPlus.filter(items, query, {key: 'label'})
const duration = Math.round(performance.now() - startTime)

this.metricsReporter.sendFilterEvent(duration, items.length, this.scoringSystem)
this.metricsReporter.sendFilterEvent(duration, items.length, 'fuzzaldrin-plus')

return results
}
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"async": "0.2.6",
"atom-select-list": "^0.7.0",
"fs-plus": "^3.0.0",
"fuzzaldrin": "^2.0",
"fuzzaldrin-plus": "^0.6.0",
"@atom/fuzzy-native": "^1.1.2",
"humanize-plus": "~1.8.2",
"minimatch": "~3.0.3",
"temp": "~0.8.1",
Expand Down