Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify and bundle fuzzy-finder #515

Merged
merged 18 commits into from May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -66,7 +66,7 @@
"fs-admin": "0.19.0",
"fs-plus": "^3.1.1",
"fstream": "1.0.12",
"fuzzy-finder": "https://codeload.github.com/atom/fuzzy-finder/legacy.tar.gz/refs/tags/v1.14.3",
"fuzzy-finder": "file:packages/fuzzy-finder",
"git-diff": "file:packages/git-diff",
"git-utils": "5.7.1",
"github": "https://codeload.github.com/pulsar-edit/github/tar.gz/refs/tags/v0.36.15-pretranspiled",
Expand Down Expand Up @@ -204,7 +204,7 @@
"encoding-selector": "file:./packages/encoding-selector",
"exception-reporting": "file:./packages/exception-reporting",
"find-and-replace": "file:./packages/find-and-replace",
"fuzzy-finder": "1.14.3",
"fuzzy-finder": "file:packages/fuzzy-finder",
"github": "0.36.14",
"git-diff": "file:./packages/git-diff",
"go-to-line": "file:./packages/go-to-line",
Expand Down
2 changes: 1 addition & 1 deletion packages/README.md
Expand Up @@ -32,7 +32,7 @@ See [RFC 003](https://github.com/atom/atom/blob/master/docs/rfcs/003-consolidate
| **encoding-selector** | [`./encoding-selector`](./encoding-selector) | |
| **exception-reporting** | [`./exception-reporting`](./exception-reporting) | |
| **find-and-replace** | [`./find-and-replace`][find-and-replace] | |
| **fuzzy-finder** | [`pulsar-edit/fuzzy-finder`][fuzzy-finder] | |
| **fuzzy-finder** | [`./fuzzy-finder`][fuzzy-finder] | |
| **github** | [`pulsar-edit/github`][github] | |
| **git-diff** | [`./git-diff`](./git-diff) | |
| **go-to-line** | [`./go-to-line`](./go-to-line) | |
Expand Down
1 change: 1 addition & 0 deletions packages/fuzzy-finder/.gitignore
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions packages/fuzzy-finder/CONTRIBUTING.md
@@ -0,0 +1 @@
[See how you can contribute](https://github.com/pulsar-edit/.github/blob/main/CONTRIBUTING.md)
20 changes: 20 additions & 0 deletions packages/fuzzy-finder/LICENSE.md
@@ -0,0 +1,20 @@
Copyright (c) 2014 GitHub Inc.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 changes: 22 additions & 0 deletions packages/fuzzy-finder/README.md
@@ -0,0 +1,22 @@
# Fuzzy Finder package

Quickly find and open files using <kbd>cmd-t</kbd>.

* <kbd>cmd-t</kbd> or <kbd>cmd-p</kbd> to open the file finder
* <kbd>cmd-b</kbd> to open the list of open buffers
* <kbd>cmd-shift-b</kbd> to open the list of Git modified and untracked files

When opening a file, you can control the behavior.

* <kbd>enter</kbd> defaults to opening the selected file without leaving the current pane
* <kbd>shift-enter</kbd> defaults to switching to another pane if the file is already open there
* <kbd>cmd-k</kbd> <kbd>right</kbd> (or any other directional arrow) will open the highlighted file in a new pane on the side indicated by the arrow
* Adding `:<line number>` to the end of your search will go directly to the line number you specify, or the last line if the number is larger

Turning on the "Search All Panes" setting reverses the behavior of <kbd>enter</kbd> and <kbd>shift-enter</kbd> so <kbd>enter</kbd> opens the file in any pane and <kbd>shift-enter</kbd> creates a new tab in the current pane.

This package uses both the `core.ignoredNames` and `fuzzy-finder.ignoredNames` config settings to filter out files and folders that will not be shown. Both of those config settings are interpreted as arrays of [minimatch](https://github.com/isaacs/minimatch) glob patterns.

This package also will also not show Git ignored files when the `core.excludeVcsIgnoredPaths` is enabled.

![](https://f.cloud.github.com/assets/671378/2241456/100db6b8-9cd3-11e3-9b3a-569c6b50cc60.png)
44 changes: 44 additions & 0 deletions packages/fuzzy-finder/docs/events.md
@@ -0,0 +1,44 @@
# Events specification

This document specifies all the data (along with the format) which gets sent from the Fuzzy Finder package to the GitHub analytics pipeline. This document follows the same format and nomenclature as the [Atom Core Events spec](https://github.com/atom/metrics/blob/master/docs/events.md).

## Counters

| counter name | description |
|-------|-------|
| `show-enable-prompt` | Number of times the prompt to enable fast mode is shown |
| `click-enable-prompt` | Number of clicks on the "enable fast mode" prompt |
| `confirm-enable-prompt` | Number of confirmations on the "enable fast mode" notification |
| `cancel-enable-prompt` | Number of cancels on the "enable fast mode" notification |
| `show-disable-prompt` | Number of times the prompt to disable fast mode is shown |
| `click-disable-prompt` | Number of clicks on the "disable fast mode" prompt |
| `confirm-disable-prompt` | Number of confirmations on the "disable fast mode" notification |
| `cancel-disable-prompt` | Number of cancels on the "disable fast mode" notification |

## Timing events

#### Time to crawl the project

* **eventType**: `fuzzy-finder-v1`
* **metadata**

| field | value |
|-------|-------|
| `ec` | `time-to-crawl`
| `el` | Crawler type (`ripgrep` or `fs`)
| `ev` | Number of crawled files

#### Time to filter results

* **eventType**: `fuzzy-finder-v1`
* **metadata**

| field | value |
|-------|-------|
| `ec` | `time-to-filter`
| `el` | Scoring system (`alternate` or `fast`)
| `ev` | Number of items in the list

## Standard events

Currently the Fuzzy Finder does not log any standard events.
20 changes: 20 additions & 0 deletions packages/fuzzy-finder/keymaps/fuzzy-finder.cson
@@ -0,0 +1,20 @@
'.platform-darwin':
'cmd-t': 'fuzzy-finder:toggle-file-finder'
'cmd-p': 'fuzzy-finder:toggle-file-finder'
'cmd-b': 'fuzzy-finder:toggle-buffer-finder'
'cmd-B': 'fuzzy-finder:toggle-git-status-finder'

'.platform-win32':
'ctrl-t': 'fuzzy-finder:toggle-file-finder'
'ctrl-p': 'fuzzy-finder:toggle-file-finder'
'ctrl-b': 'fuzzy-finder:toggle-buffer-finder'
'ctrl-B': 'fuzzy-finder:toggle-git-status-finder'

'.platform-linux':
'ctrl-t': 'fuzzy-finder:toggle-file-finder'
'ctrl-p': 'fuzzy-finder:toggle-file-finder'
'ctrl-b': 'fuzzy-finder:toggle-buffer-finder'
'ctrl-B': 'fuzzy-finder:toggle-git-status-finder'

'.fuzzy-finder atom-text-editor[mini]':
'shift-enter': 'fuzzy-finder:invert-confirm'
89 changes: 89 additions & 0 deletions packages/fuzzy-finder/lib/buffer-view.js
@@ -0,0 +1,89 @@
const FuzzyFinderView = require('./fuzzy-finder-view')
const path = require('path')

module.exports =
class BufferView extends FuzzyFinderView {
setTeletypeService (teletypeService) {
this.teletypeService = teletypeService
}

getEmptyMessage () {
return 'No open editors'
}

async toggle () {
if (this.panel && this.panel.isVisible()) {
this.cancel()
} else {
const items = this.sortItems(await this.buildItems())
if (items.length > 0) {
this.show()
await this.setItems(items)
}
}
}

async buildItems () {
const itemsByURI = new Map()

const remoteEditorsByURI = await this.getRemoteEditorsByURI()
const projectHasMultipleDirectories = atom.project.getDirectories().length > 1
const localEditors = atom.workspace.getTextEditors()
for (let i = 0; i < localEditors.length; i++) {
const localEditor = localEditors[i]
const localEditorURI = localEditor.getURI()
const localEditorPath = localEditor.getPath()
if (!localEditorURI) continue
if (itemsByURI.has(localEditorURI)) continue

const item = {uri: localEditorURI}

const remoteEditor = remoteEditorsByURI.get(localEditorURI)
if (remoteEditor) {
item.filePath = remoteEditor.path
item.label = `@${remoteEditor.hostGitHubUsername}: ${remoteEditor.path}`
item.ownerGitHubUsername = remoteEditor.hostGitHubUsername
} else {
const [projectRootPath, projectRelativePath] = atom.project.relativizePath(localEditorPath)
item.filePath = localEditorPath
item.label =
projectRootPath && projectHasMultipleDirectories
? path.join(path.basename(projectRootPath), projectRelativePath)
: projectRelativePath
}

if (localEditor.lastOpened != null) {
item.lastOpened = localEditor.lastOpened
}

itemsByURI.set(localEditorURI, item)
}

return Array.from(itemsByURI.values())
}

sortItems (items) {
const activeEditor = atom.workspace.getActiveTextEditor()
const activeEditorURI = activeEditor ? activeEditor.getURI() : null
items.sort((a, b) => {
if (a.uri === activeEditorURI) {
return 1
} else if (b.uri === activeEditorURI) {
return -1
} else {
return (b.lastOpened || 1) - (a.lastOpened || 1)
}
})
return items
}

async getRemoteEditorsByURI () {
const remoteEditorsByURI = new Map()
const remoteEditors = this.teletypeService ? await this.teletypeService.getRemoteEditors() : []
for (var i = 0; i < remoteEditors.length; i++) {
const remoteEditor = remoteEditors[i]
remoteEditorsByURI.set(remoteEditor.uri, remoteEditor)
}
return remoteEditorsByURI
}
}
26 changes: 26 additions & 0 deletions packages/fuzzy-finder/lib/default-file-icons.js
@@ -0,0 +1,26 @@
const fs = require('fs-plus')
const path = require('path')

class DefaultFileIcons {
iconClassForPath (filePath) {
const extension = path.extname(filePath)

if (fs.isSymbolicLinkSync(filePath)) {
return 'icon-file-symlink-file'
} else if (fs.isReadmePath(filePath)) {
return 'icon-book'
} else if (fs.isCompressedExtension(extension)) {
return 'icon-file-zip'
} else if (fs.isImageExtension(extension)) {
return 'icon-file-media'
} else if (fs.isPdfExtension(extension)) {
return 'icon-file-pdf'
} else if (fs.isBinaryExtension(extension)) {
return 'icon-file-binary'
} else {
return 'icon-file-text'
}
}
}

module.exports = new DefaultFileIcons()