Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 5b098d7

Browse files
author
Stephen Gutekanst
committed
all: release v1.0.5
1 parent 46c14d2 commit 5b098d7

File tree

3 files changed

+51
-33
lines changed

3 files changed

+51
-33
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.5 - Fixed search shortcut.
2+
3+
- Updated the search URL to reflect a recent Sourcegraph.com change.
4+
15
## 1.0.0 - Initial Release
26

3-
- basic Open File & Search functionality.
7+
- Basic Open File & Search functionality.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ Please file an issue: https://github.com/sourcegraph/sourcegraph-atom/issues/new
4949

5050
To develop the plugin:
5151

52-
- `git clone` the repository into `~/.atom/Packages/sourcegraph` (lowercase `packages` on Mac)
52+
- `git clone` the repository into `~/.atom/Packages/sourcegraph` (lowercase `packages` on Mac), `npm install` and open in Atom.
5353
- Use <kbd>Cmd+Shift+P</kbd> to open the command pallette, and choose `Window: Reload` to reload the extension in the current Atom window.
5454
- Atom does some really bad things with respect to reopening the workspace, so `File` -> `Reopen Project` and `View` -> `Toggle Tree View` (<kbd>Cmd+\\</kbd>) are your friends here. Consider using a separate editor to make changes.
5555
- To release a new version, you MSUT update the following files:
5656
1. `CHANGELOG.md` (describe ALL changes)
5757
3. `lib/sourcegraph.js` (`VERSION` constant)
58-
4. `git commit -m "all: release v<THE VERSION>` and `git push`.
58+
4. `git commit -m "all: release v<THE VERSION>" && git push`
5959
5. `apm publish <major|minor|patch>`
6060

6161

lib/sourcegraph.js

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const execa = require('execa')
77
const url = require('url')
88
const path = require('path')
99

10-
const VERSION = "v1.0.4"
10+
const VERSION = "v1.0.5"
1111

1212
// gitRemotes returns the names of all git remotes, e.g. ["origin", "foobar"]
1313
async function gitRemotes(repoDir: string) {
@@ -53,25 +53,32 @@ async function gitBranch(repoDir: string) {
5353
}
5454

5555
function sourcegraphURL() {
56-
const url = atom.config.get('sourcegraph.URL');
56+
const url = atom.config.get('sourcegraph.URL')
5757
if (!url.endsWith("/")) {
5858
return url + "/"
5959
}
6060
return url
6161
}
6262

6363
// repoInfo returns the Sourcegraph repository URI, and the file path relative
64-
// to the repository root. If the repository URI cannot be determined, an
65-
// exception is thrown.
64+
// to the repository root. If the repository URI cannot be determined, empty
65+
// strings are returned.
6666
async function repoInfo(fileName: string) {
67-
// Determine repository root directory.
68-
const fileDir = path.dirname(fileName)
69-
const repoRoot = await gitRootDir(fileDir)
70-
71-
// Determine file path, relative to repository root.
72-
const remoteURL = await gitDefaultRemoteURL(repoRoot)
73-
const branch = await gitBranch(repoRoot)
74-
const fileRel = fileName.slice(repoRoot.length + 1)
67+
let remoteURL = ""
68+
let branch = ""
69+
let fileRel = ""
70+
try{
71+
// Determine repository root directory.
72+
const fileDir = path.dirname(fileName)
73+
const repoRoot = await gitRootDir(fileDir)
74+
75+
// Determine file path, relative to repository root.
76+
remoteURL = await gitDefaultRemoteURL(repoRoot)
77+
branch = await gitBranch(repoRoot)
78+
fileRel = fileName.slice(repoRoot.length + 1)
79+
} catch (e) {
80+
console.log("repoInfo:", e)
81+
}
7582
return [remoteURL, branch, fileRel]
7683
}
7784

@@ -84,40 +91,47 @@ async function open() {
8491
}
8592
let r = editor.getSelectedBufferRange()
8693

87-
try {
88-
const [remoteURL, branch, fileRel] = await repoInfo(editor.getPath())
89-
90-
// Open in browser.
91-
opn(`${sourcegraphURL()}-/editor`
92-
+ `?remote_url=${encodeURIComponent(remoteURL)}`
93-
+ `&branch=${encodeURIComponent(branch)}`
94-
+ `&file=${encodeURIComponent(fileRel)}`
95-
+ `&editor=${encodeURIComponent("Atom")}`
96-
+ `&version=${encodeURIComponent(VERSION)}`
97-
+ `&start_row=${encodeURIComponent(r.start.row)}`
98-
+ `&start_col=${encodeURIComponent(r.start.column)}`
99-
+ `&end_row=${encodeURIComponent(r.end.row)}`
100-
+ `&end_col=${encodeURIComponent(r.end.column)}`)
101-
} catch (e) {
102-
console.error(e)
94+
const [remoteURL, branch, fileRel] = await repoInfo(editor.getPath())
95+
if (remoteURL == "") {
96+
return
10397
}
98+
99+
// Open in browser.
100+
opn(`${sourcegraphURL()}-/editor`
101+
+ `?remote_url=${encodeURIComponent(remoteURL)}`
102+
+ `&branch=${encodeURIComponent(branch)}`
103+
+ `&file=${encodeURIComponent(fileRel)}`
104+
+ `&editor=${encodeURIComponent("Atom")}`
105+
+ `&version=${encodeURIComponent(VERSION)}`
106+
+ `&start_row=${encodeURIComponent(r.start.row)}`
107+
+ `&start_col=${encodeURIComponent(r.start.column)}`
108+
+ `&end_row=${encodeURIComponent(r.end.row)}`
109+
+ `&end_col=${encodeURIComponent(r.end.column)}`)
104110
}
105111

106112
// search is the command implementation for searching a selection on
107113
// Sourcegraph.
108-
function search() {
114+
async function search() {
109115
let editor = atom.workspace.getActiveTextEditor()
110116
if (!editor) {
111117
return
112118
}
113119

120+
const [remoteURL, branch, fileRel] = await repoInfo(editor.getPath())
121+
114122
let query = editor.getSelectedText()
115123
if (query == "") {
116124
return // nothing to query
117125
}
118126

119127
// Search in browser.
120-
opn(`${sourcegraphURL()}-/editor/?search=${encodeURIComponent(query)}&editor=${encodeURIComponent("Atom")}&version=${encodeURIComponent(VERSION)}`)
128+
opn(`${sourcegraphURL()}-/editor`
129+
+ `?remote_url=${encodeURIComponent(remoteURL)}`
130+
+ `&branch=${encodeURIComponent(branch)}`
131+
+ `&file=${encodeURIComponent(fileRel)}`
132+
+ `&editor=${encodeURIComponent("Atom")}`
133+
+ `&version=${encodeURIComponent(VERSION)}`
134+
+ `&search=${encodeURIComponent(query)}`)
121135
}
122136

123137
export default {

0 commit comments

Comments
 (0)