Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit be1d796

Browse files
Code review: Better names, less comments
1 parent 8ed0d11 commit be1d796

File tree

5 files changed

+23
-30
lines changed

5 files changed

+23
-30
lines changed

‎server/src/analyser.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,14 @@ export default class Analyzer {
5757
})
5858
}
5959

60-
// Global map from uri to the tree-sitter document.
61-
private documents: Documents = {}
60+
private uriToTreeSitterDocument: Documents = {}
6261

63-
// Global mapping from uri to the contents of the file at that uri.
6462
// We need this to find the word at a given point etc.
65-
private texts: Texts = {}
63+
private uriToFileContent: Texts = {}
6664

67-
// Global map of all the declarations that we've seen, indexed by file
68-
// and then name.
69-
private declarations: FileDeclarations = {}
65+
private uriToDeclarations: FileDeclarations = {}
7066

71-
// Global mapping from tree-sitter node type to vscode SymbolKind
72-
private kinds: Kinds = {
67+
private treeSitterTypeToLSPKind: Kinds = {
7368
// These keys are using underscores as that's the naming convention in tree-sitter.
7469
environment_variable_assignment: LSP.SymbolKind.Variable,
7570
function_definition: LSP.SymbolKind.Function,
@@ -80,8 +75,8 @@ export default class Analyzer {
8075
*/
8176
public findDefinition(name: string): LSP.Location[] {
8277
const symbols: LSP.SymbolInformation[] = []
83-
Object.keys(this.declarations).forEach(uri => {
84-
const declarationNames = this.declarations[uri][name] || []
78+
Object.keys(this.uriToDeclarations).forEach(uri => {
79+
const declarationNames = this.uriToDeclarations[uri][name] || []
8580
declarationNames.forEach(d => symbols.push(d))
8681
})
8782
return symbols.map(s => s.location)
@@ -92,7 +87,7 @@ export default class Analyzer {
9287
*/
9388
public findReferences(name: string): LSP.Location[] {
9489
const locations = []
95-
Object.keys(this.documents).forEach(uri => {
90+
Object.keys(this.uriToTreeSitterDocument).forEach(uri => {
9691
this.findOccurrences(uri, name).forEach(l => locations.push(l))
9792
})
9893
return locations
@@ -103,8 +98,8 @@ export default class Analyzer {
10398
* It's currently not scope-aware.
10499
*/
105100
public findOccurrences(uri: string, query: string): LSP.Location[] {
106-
const doc = this.documents[uri]
107-
const contents = this.texts[uri]
101+
const doc = this.uriToTreeSitterDocument[uri]
102+
const contents = this.uriToFileContent[uri]
108103

109104
const locations = []
110105

@@ -134,7 +129,7 @@ export default class Analyzer {
134129
* Find all symbol definitions in the given file.
135130
*/
136131
public findSymbols(uri: string): LSP.SymbolInformation[] {
137-
const declarationsInFile = this.declarations[uri] || []
132+
const declarationsInFile = this.uriToDeclarations[uri] || []
138133
const ds = []
139134
Object.keys(declarationsInFile).forEach(n => {
140135
declarationsInFile[n].forEach(d => ds.push(d))
@@ -155,9 +150,9 @@ export default class Analyzer {
155150
d.setInputString(contents)
156151
d.parse()
157152

158-
this.documents[uri] = d
159-
this.declarations[uri] = {}
160-
this.texts[uri] = contents
153+
this.uriToTreeSitterDocument[uri] = d
154+
this.uriToDeclarations[uri] = {}
155+
this.uriToFileContent[uri] = contents
161156

162157
const problems = []
163158

@@ -174,17 +169,17 @@ export default class Analyzer {
174169
} else if (TreeSitterUtil.isDefinition(n)) {
175170
const named = n.firstNamedChild
176171
const name = contents.slice(named.startIndex, named.endIndex)
177-
const namedDeclarations = this.declarations[uri][name] || []
172+
const namedDeclarations = this.uriToDeclarations[uri][name] || []
178173

179174
namedDeclarations.push(
180175
LSP.SymbolInformation.create(
181176
name,
182-
this.kinds[n.type],
177+
this.treeSitterTypeToLSPKind[n.type],
183178
TreeSitterUtil.range(named),
184179
uri,
185180
),
186181
)
187-
this.declarations[uri][name] = namedDeclarations
182+
this.uriToDeclarations[uri][name] = namedDeclarations
188183
}
189184
})
190185

@@ -195,8 +190,8 @@ export default class Analyzer {
195190
* Find the full word at the given point.
196191
*/
197192
public wordAtPoint(uri: string, line: number, column: number): string | null {
198-
const document = this.documents[uri]
199-
const contents = this.texts[uri]
193+
const document = this.uriToTreeSitterDocument[uri]
194+
const contents = this.uriToFileContent[uri]
200195

201196
const node = document.rootNode.namedDescendantForPosition({ row: line, column })
202197

‎server/src/executables.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class Executables {
1414
*/
1515
public static fromPath(path: string): Promise<Executables> {
1616
const paths = path.split(':')
17-
const promises = paths.map(x => _executables(x))
17+
const promises = paths.map(x => findExecutablesInPath(x))
1818
return Promise.all(promises)
1919
.then(ArrayUtil.flatten)
2020
.then(ArrayUtil.uniq)
@@ -47,7 +47,7 @@ export default class Executables {
4747
* For now it simply tries to look up the MAN documentation.
4848
*/
4949
public documentation(executable: string): Promise<string> {
50-
return ShUtil.exec(`man ${executable} | col -b`).then(doc => {
50+
return ShUtil.execShellScript(`man ${executable} | col -b`).then(doc => {
5151
return !doc
5252
? Promise.resolve(`No MAN page for ${executable}`)
5353
: Promise.resolve(doc)
@@ -56,10 +56,9 @@ export default class Executables {
5656
}
5757

5858
/**
59-
* Find all the executables on the given path.
6059
* Only returns direct children, or the path itself if it's an executable.
6160
*/
62-
function _executables(path: string): Promise<string[]> {
61+
function findExecutablesInPath(path: string): Promise<string[]> {
6362
return new Promise((resolve, _) => {
6463
Fs.lstat(path, (err, stat) => {
6564
if (err) {

‎server/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,5 @@ export function listen() {
3030
}))
3131
})
3232

33-
// Listen on the connection
3433
connection.listen()
3534
}

‎server/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Executables from './executables'
1010
export default class BashServer {
1111
/**
1212
* Initialize the server based on a connection to the client and the protocols
13-
* initialization paramters.
13+
* initialization parameters.
1414
*/
1515
public static initialize(
1616
connection: LSP.Connection,

‎server/src/util/sh.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as ChildProcess from 'child_process'
33
/**
44
* Execute the following sh program.
55
*/
6-
export function exec(body: string): Promise<string> {
6+
export function execShellScript(body: string): Promise<string> {
77
const args = ['-c', body]
88
const process = ChildProcess.spawn('sh', args)
99

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /