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 e44ce78

Browse files
committed
Change signatures to use SymbolKind rather than custom type
1 parent ac48675 commit e44ce78

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

‎server/src/analyser.ts‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,12 @@ export default class Analyzer {
283283
position,
284284
uri,
285285
word,
286-
type,
286+
kind,
287287
}: {
288288
position: LSP.Position
289289
uri: string
290290
word: string
291-
type: 'variable'|'function'
291+
kind: LSP.SymbolKind
292292
}): { declaration: LSP.Location | null; parent: LSP.Location | null } {
293293
const node = this.nodeAtPoint(uri, position.line, position.character)
294294

@@ -303,7 +303,7 @@ export default class Analyzer {
303303
let boundary = position.line
304304
while (parent) {
305305
if (
306-
type === 'variable' &&
306+
kind === LSP.SymbolKind.Variable &&
307307
parent.type === 'function_definition' &&
308308
parent.lastChild
309309
) {
@@ -357,7 +357,7 @@ export default class Analyzer {
357357
let definedVariableInExpression = false
358358

359359
if (
360-
type === 'variable' &&
360+
kind === LSP.SymbolKind.Variable &&
361361
(['declaration_command', 'variable_assignment', 'for_statement'].includes(
362362
n.type,
363363
) ||
@@ -370,7 +370,10 @@ export default class Analyzer {
370370
!!definedSymbol &&
371371
(definedSymbol.endPosition.column < position.character ||
372372
definedSymbol.endPosition.row < position.line)
373-
} else if (type === 'function' && n.type === 'function_definition') {
373+
} else if (
374+
kind === LSP.SymbolKind.Function &&
375+
n.type === 'function_definition'
376+
) {
374377
definedSymbol = n.firstNamedChild
375378
}
376379

@@ -468,13 +471,13 @@ export default class Analyzer {
468471
public findOccurrencesWithin({
469472
uri,
470473
word,
471-
type,
474+
kind,
472475
start,
473476
scope,
474477
}: {
475478
uri: string
476479
word: string
477-
type: 'variable'|'function'
480+
kind: LSP.SymbolKind
478481
start?: LSP.Position
479482
scope?: LSP.Range
480483
}): LSP.Range[] {
@@ -486,7 +489,7 @@ export default class Analyzer {
486489
)
487490
: null
488491
const baseNode =
489-
scopeNode && (type === 'variable' || scopeNode.type === 'subshell')
492+
scopeNode && (kind === LSP.SymbolKind.Variable || scopeNode.type === 'subshell')
490493
? scopeNode
491494
: this.uriToAnalyzedDocument[uri]?.tree.rootNode
492495

@@ -495,14 +498,16 @@ export default class Analyzer {
495498
}
496499

497500
const typeOfDescendants =
498-
type === 'variable' ? 'variable_name' : ['function_definition', 'command_name']
501+
kind === LSP.SymbolKind.Variable
502+
? 'variable_name'
503+
: ['function_definition', 'command_name']
499504
const startPosition = start
500505
? { row: start.line, column: start.character }
501506
: baseNode.startPosition
502507

503508
const ignoredRanges: LSP.Range[] = []
504509
const filter =
505-
type === 'variable'
510+
kind === LSP.SymbolKind.Variable
506511
? (n: Parser.SyntaxNode) => {
507512
if (n.text !== word) {
508513
return false
@@ -800,7 +805,7 @@ export default class Analyzer {
800805

801806
public symbolAtPointFromTextPosition(
802807
params: LSP.TextDocumentPositionParams,
803-
): { word: string; range: LSP.Range; type: 'variable'|'function' } | null {
808+
): { word: string; range: LSP.Range; kind: LSP.SymbolKind } | null {
804809
const node = this.nodeAtPoint(
805810
params.textDocument.uri,
806811
params.position.line,
@@ -819,7 +824,10 @@ export default class Analyzer {
819824
return {
820825
word: node.text,
821826
range: TreeSitterUtil.range(node),
822-
type: node.type === 'variable_name' ? 'variable' : 'function',
827+
kind:
828+
node.type === 'variable_name'
829+
? LSP.SymbolKind.Variable
830+
: LSP.SymbolKind.Function,
823831
}
824832
}
825833

‎server/src/server.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ export default class BashServer {
731731

732732
if (
733733
!symbol ||
734-
(symbol.type === 'variable' &&
734+
(symbol.kind === LSP.SymbolKind.Variable &&
735735
(symbol.word === '_' || !/^[a-z_][\w]*$/i.test(symbol.word)))
736736
) {
737737
return null
@@ -749,28 +749,28 @@ export default class BashServer {
749749
}
750750

751751
if (
752-
symbol.type === 'variable' &&
752+
symbol.kind === LSP.SymbolKind.Variable &&
753753
(params.newName === '_' || !/^[a-z_][\w]*$/i.test(params.newName))
754754
) {
755755
this.throwResponseError('Invalid variable name given.')
756756
}
757757

758-
if (symbol.type === 'function' && params.newName.includes('$')) {
758+
if (symbol.kind === LSP.SymbolKind.Function && params.newName.includes('$')) {
759759
this.throwResponseError('Invalid function name given.')
760760
}
761761

762762
const { declaration, parent } = this.analyzer.findOriginalDeclaration({
763763
position: params.position,
764764
uri: params.textDocument.uri,
765765
word: symbol.word,
766-
type: symbol.type,
766+
kind: symbol.kind,
767767
})
768768

769769
if (!declaration) {
770770
const ranges = this.analyzer.findOccurrencesWithin({
771771
uri: params.textDocument.uri,
772772
word: symbol.word,
773-
type: symbol.type,
773+
kind: symbol.kind,
774774
})
775775

776776
return <LSP.WorkspaceEdit>{
@@ -787,7 +787,7 @@ export default class BashServer {
787787
const ranges = this.analyzer.findOccurrencesWithin({
788788
uri: params.textDocument.uri,
789789
word: symbol.word,
790-
type: symbol.type,
790+
kind: symbol.kind,
791791
start: declaration.range.start,
792792
scope: parent.range,
793793
})

0 commit comments

Comments
(0)

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