Skip to content

Commit 6434dc7

Browse files
committed
Correct documentation path
1 parent e87ef23 commit 6434dc7

File tree

4 files changed

+40
-25
lines changed

4 files changed

+40
-25
lines changed

server/src/__tests__/analyzer.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import * as path from 'path'
2-
3-
import { FIXTURE_DOCUMENT, FIXTURE_FOLDER, FIXTURE_URI } from '../../../testing/fixtures'
1+
import {
2+
FIXTURE_DOCUMENT,
3+
FIXTURE_FOLDER,
4+
FIXTURE_URI,
5+
REPO_ROOT_FOLDER,
6+
} from '../../../testing/fixtures'
47
import { getMockConnection } from '../../../testing/mocks'
58
import Analyzer from '../analyser'
69
import { getDefaultConfiguration } from '../config'
@@ -10,7 +13,6 @@ import * as fsUtil from '../util/fs'
1013
let analyzer: Analyzer
1114

1215
const CURRENT_URI = 'dummy-uri.sh'
13-
const REPO_ROOT_FOLDER = path.resolve(path.join(FIXTURE_FOLDER, '../..'))
1416
const mockConsole = getMockConnection().console
1517

1618
// if you add a .sh file to testing/fixtures, update this value

server/src/__tests__/server.test.ts

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@ import * as Path from 'path'
33
import * as LSP from 'vscode-languageserver/node'
44
import { CodeAction } from 'vscode-languageserver/node'
55

6-
import FIXTURE_DOCUMENT, { FIXTURE_FOLDER, FIXTURE_URI } from '../../../testing/fixtures'
6+
import {
7+
FIXTURE_DOCUMENT,
8+
FIXTURE_FOLDER,
9+
FIXTURE_URI,
10+
REPO_ROOT_FOLDER,
11+
} from '../../../testing/fixtures'
712
import { getMockConnection } from '../../../testing/mocks'
813
import LspServer from '../server'
914
import { CompletionItemDataType } from '../types'
1015

11-
async function initializeServer() {
16+
async function initializeServer(
17+
{ rootPath }: { rootPath?: string } = { rootPath: FIXTURE_FOLDER },
18+
) {
1219
const diagnostics: Array<LSP.PublishDiagnosticsParams | undefined> = []
1320

1421
const connection = getMockConnection()
1522

1623
const server = await LspServer.initialize(connection, {
17-
rootPath: FIXTURE_FOLDER,
24+
rootPath,
1825
rootUri: null,
1926
processId: 42,
2027
capabilities: {} as any,
@@ -484,7 +491,7 @@ describe('server', () => {
484491
"name": "BLUE",
485492
"type": 3,
486493
},
487-
"documentation": "### Variable: **BLUE** - *defined in ../extension.inc*",
494+
"documentation": "### Variable: **BLUE** - *defined in extension.inc*",
488495
"kind": 6,
489496
"label": "BLUE",
490497
},
@@ -513,7 +520,7 @@ describe('server', () => {
513520
"name": "add_a_user",
514521
"type": 3,
515522
},
516-
"documentation": "### Function: **add_a_user** - *defined in ../issue101.sh*
523+
"documentation": "### Function: **add_a_user** - *defined in issue101.sh*
517524
518525
\`\`\`txt
519526
Helper function to add a user
@@ -561,7 +568,7 @@ describe('server', () => {
561568
})
562569

563570
it('responds to onCompletion with all variables when starting to expand parameters', async () => {
564-
const { connection } = await initializeServer()
571+
const { connection } = await initializeServer({ rootPath: REPO_ROOT_FOLDER })
565572

566573
const onCompletion = connection.onCompletion.mock.calls[0][0]
567574

@@ -600,7 +607,7 @@ describe('server', () => {
600607
"name": "RED",
601608
"type": 3,
602609
},
603-
"documentation": "### Variable: **RED** - *defined in ../extension.inc*",
610+
"documentation": "### Variable: **RED** - *defined in extension.inc*",
604611
"kind": 6,
605612
"label": "RED",
606613
},
@@ -609,7 +616,7 @@ describe('server', () => {
609616
"name": "GREEN",
610617
"type": 3,
611618
},
612-
"documentation": "### Variable: **GREEN** - *defined in ../extension.inc*",
619+
"documentation": "### Variable: **GREEN** - *defined in extension.inc*",
613620
"kind": 6,
614621
"label": "GREEN",
615622
},
@@ -618,7 +625,7 @@ describe('server', () => {
618625
"name": "BLUE",
619626
"type": 3,
620627
},
621-
"documentation": "### Variable: **BLUE** - *defined in ../extension.inc*",
628+
"documentation": "### Variable: **BLUE** - *defined in extension.inc*",
622629
"kind": 6,
623630
"label": "BLUE",
624631
},
@@ -627,7 +634,7 @@ describe('server', () => {
627634
"name": "RESET",
628635
"type": 3,
629636
},
630-
"documentation": "### Variable: **RESET** - *defined in ../extension.inc*",
637+
"documentation": "### Variable: **RESET** - *defined in extension.inc*",
631638
"kind": 6,
632639
"label": "RESET",
633640
},
@@ -636,7 +643,7 @@ describe('server', () => {
636643
"name": "USER",
637644
"type": 3,
638645
},
639-
"documentation": "### Variable: **USER** - *defined in ../issue101.sh*",
646+
"documentation": "### Variable: **USER** - *defined in issue101.sh*",
640647
"kind": 6,
641648
"label": "USER",
642649
},
@@ -645,7 +652,7 @@ describe('server', () => {
645652
"name": "PASSWORD",
646653
"type": 3,
647654
},
648-
"documentation": "### Variable: **PASSWORD** - *defined in ../issue101.sh*",
655+
"documentation": "### Variable: **PASSWORD** - *defined in issue101.sh*",
649656
"kind": 6,
650657
"label": "PASSWORD",
651658
},
@@ -654,14 +661,23 @@ describe('server', () => {
654661
"name": "COMMENTS",
655662
"type": 3,
656663
},
657-
"documentation": "### Variable: **COMMENTS** - *defined in ../issue101.sh*
664+
"documentation": "### Variable: **COMMENTS** - *defined in issue101.sh*
658665
659666
\`\`\`txt
660667
Having shifted twice, the rest is now comments ...
661668
\`\`\`",
662669
"kind": 6,
663670
"label": "COMMENTS",
664671
},
672+
Object {
673+
"data": Object {
674+
"name": "tag",
675+
"type": 3,
676+
},
677+
"documentation": "### Variable: **tag** - *defined in ../../scripts/tag-release.inc*",
678+
"kind": 6,
679+
"label": "tag",
680+
},
665681
]
666682
`)
667683
})

server/src/server.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as Process from 'child_process'
2-
import * as Path from 'path'
1+
import { spawnSync } from 'child_process'
2+
import * as path from 'path'
33
import * as TurndownService from 'turndown'
44
import { isDeepStrictEqual } from 'util'
55
import * as LSP from 'vscode-languageserver/node'
@@ -352,7 +352,7 @@ export default class BashServer {
352352
const hoverHeader = `### ${symbolKindToDescription(symbol.kind)}: **${symbol.name}**`
353353
const symbolLocation =
354354
symbolUri !== currentUri
355-
? `in ${Path.relative(currentUri, symbolUri)}`
355+
? `in ${path.relative(path.dirname(currentUri), symbolUri)}`
356356
: `on line ${symbolStarLine + 1}`
357357

358358
return `${hoverHeader} - *defined ${symbolLocation}*${symbolDocumentation}`
@@ -799,10 +799,7 @@ const getMarkdownContent = (documentation: string): LSP.MarkupContent => ({
799799

800800
function getCommandOptions(name: string, word: string): string[] {
801801
// TODO: The options could be cached.
802-
const options = Process.spawnSync(Path.join(__dirname, '../src/get-options.sh'), [
803-
name,
804-
word,
805-
])
802+
const options = spawnSync(path.join(__dirname, '../src/get-options.sh'), [name, word])
806803

807804
if (options.status !== 0) {
808805
return []

testing/fixtures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ export const FIXTURE_DOCUMENT: Record<FIXTURE_KEY, TextDocument> = (
3535
return acc
3636
}, {} as any)
3737

38-
export default FIXTURE_DOCUMENT
38+
export const REPO_ROOT_FOLDER = path.resolve(path.join(FIXTURE_FOLDER, '../..'))

0 commit comments

Comments
 (0)