Skip to content

Commit

Permalink
Chore: Add shebang to embedded bash documents
Browse files Browse the repository at this point in the history
  • Loading branch information
idillon-sfl committed Dec 12, 2023
1 parent ab6a2c8 commit a2dc95f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions server/src/__tests__/embedded-languages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ import { generateParser } from '../tree-sitter/parser'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { type EmbeddedLanguageType } from '../lib/src/types/embedded-languages'
import { imports } from '../embedded-languages/python-support'
import { shebang } from '../embedded-languages/bash-support'

describe('Create basic embedded bash documents', () => {
beforeAll(async () => {
if (!analyzer.hasParser()) {
const parser = await generateParser()
analyzer.initialize(parser)
}
analyzer.resetAnalyzedDocuments()
})

test.each([
[
'basic',
'foo(){\nBAR=""\n}',
`${shebang}foo(){\nBAR=""\n}`
]
])('%s', async (description, input, result) => {
const embeddedContent = await createEmbeddedContent(input, 'bash')
expect(embeddedContent).toEqual(result)
})
})

describe('Create various basic embedded python documents', () => {
beforeAll(async () => {
Expand Down
3 changes: 3 additions & 0 deletions server/src/embedded-languages/bash-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import * as TreeSitterUtils from '../tree-sitter/utils'
import { initEmbeddedLanguageDoc, insertTextIntoEmbeddedLanguageDoc } from './utils'
import { type EmbeddedLanguageDoc } from '../lib/src/types/embedded-languages'

export const shebang = '#!/bin/sh\n'

export const generateBashEmbeddedLanguageDoc = (analyzedDocument: AnalyzedDocument): EmbeddedLanguageDoc => {
const embeddedLanguageDoc = initEmbeddedLanguageDoc(analyzedDocument.document, 'bash')
TreeSitterUtils.forEach(analyzedDocument.tree.rootNode, (node) => {
Expand All @@ -21,5 +23,6 @@ export const generateBashEmbeddedLanguageDoc = (analyzedDocument: AnalyzedDocume
return false
}
})
insertTextIntoEmbeddedLanguageDoc(embeddedLanguageDoc, 0, 0, shebang)
return embeddedLanguageDoc
}

0 comments on commit a2dc95f

Please sign in to comment.