From a2dc95f37aa0c32905fc99a66ac3879d373dc0e2 Mon Sep 17 00:00:00 2001 From: idillon Date: Mon, 11 Dec 2023 19:10:06 -0500 Subject: [PATCH] Chore: Add shebang to embedded bash documents --- .../src/__tests__/embedded-languages.test.ts | 22 +++++++++++++++++++ server/src/embedded-languages/bash-support.ts | 3 +++ 2 files changed, 25 insertions(+) diff --git a/server/src/__tests__/embedded-languages.test.ts b/server/src/__tests__/embedded-languages.test.ts index 52f264a14..bf860071c 100644 --- a/server/src/__tests__/embedded-languages.test.ts +++ b/server/src/__tests__/embedded-languages.test.ts @@ -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 () => { diff --git a/server/src/embedded-languages/bash-support.ts b/server/src/embedded-languages/bash-support.ts index f9176ba7d..ebf4c324d 100644 --- a/server/src/embedded-languages/bash-support.ts +++ b/server/src/embedded-languages/bash-support.ts @@ -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) => { @@ -21,5 +23,6 @@ export const generateBashEmbeddedLanguageDoc = (analyzedDocument: AnalyzedDocume return false } }) + insertTextIntoEmbeddedLanguageDoc(embeddedLanguageDoc, 0, 0, shebang) return embeddedLanguageDoc }