forked from ex3ndr/llama-coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip+feat: working on language detection, detect language for filename…
… marking
- Loading branch information
Showing
18 changed files
with
2,104 additions
and
591 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testPathIgnorePatterns: ["/node_modules/","/out/"], | ||
setupFiles: ['./jest.setup.js'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('dotenv').config(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { LanguageDescriptor } from "./languages"; | ||
|
||
export function comment(text: string, language: LanguageDescriptor): string | null { | ||
if (language.comment) { | ||
if (language.comment.end) { | ||
return `${language.comment.start} ${text} ${language.comment.end}`; | ||
} else { | ||
return `${language.comment.start} ${text}`; | ||
} | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { detectLanguage } from './detectLanguage'; | ||
|
||
describe('detectLanguage', () => { | ||
it('should detect language from happy path', () => { | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
// import path from 'path'; | ||
import path from 'path'; | ||
import { Language, languages } from './languages'; | ||
|
||
// let languages: { [key: string]: {} } = { | ||
let aliases: { [key: string]: Language } = { | ||
'typescriptreact': 'typescript', | ||
'javascriptreact': 'javascript', | ||
'jsx': 'javascript' | ||
}; | ||
|
||
// }; | ||
export function detectLanguage(uri: string, languageId: string | null): Language | null { | ||
|
||
// export function fileHeaderProcessor(uri: string, languageId: string): string | null { | ||
// let basename = path.basename(uri); | ||
// let extname = | ||
// } | ||
// Resolve aliases | ||
if (!!languageId && aliases[languageId]) { | ||
return aliases[languageId]; | ||
} | ||
|
||
// Resolve using language id | ||
if (!!languageId && !!languages[languageId as Language]) { | ||
return languageId as Language; | ||
} | ||
|
||
// Resolve using filename and extension | ||
let basename = path.basename(uri); | ||
let extname = path.extname(basename).toLowerCase(); | ||
|
||
// Check extensions | ||
for (let lang in languages) { | ||
let k = languages[lang as Language]; | ||
for (let ex of k.extensions) { | ||
if (extname === ex) { | ||
return lang as Language; | ||
} | ||
} | ||
} | ||
|
||
// Return result | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { comment } from "./comment"; | ||
import { LanguageDescriptor } from "./languages"; | ||
|
||
export function fileHeaders(content: string, uri: string, language: LanguageDescriptor | null) { | ||
let res = content; | ||
if (language) { | ||
|
||
// Add path marker | ||
let pathMarker = comment('Path: ' + uri, language); | ||
if (pathMarker) { | ||
res = pathMarker + '\n' + res; | ||
} | ||
|
||
// Add language marker | ||
let typeMarker = comment('Language: ' + language.name, language); | ||
if (typeMarker) { | ||
res = typeMarker + '\n' + res; | ||
} | ||
} | ||
return res; | ||
} |
Oops, something went wrong.