Skip to content
This repository was archived by the owner on Mar 18, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions generator/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as shell from 'shelljs'
import * as _ from 'lodash'
import * as yargs from 'yargs'
import * as tosource from 'tosource'
import * as fs from 'fs'
import * as spec from '../../languages'
import { languageSpecs, LanguageSpec } from '../../languages'

function sourcegraphID(name: string): string {
const toID = {
Expand All @@ -18,7 +16,7 @@ const doNotGenerate = ['python', 'typescript', 'go']
function main(): void {
const args = yargs
.option('languages', {
describe: spec.languages
describe: languageSpecs
.map(langSpec => langSpec.handlerArgs.languageID)
.join(','),
type: 'string',
Expand All @@ -27,7 +25,7 @@ function main(): void {
.strict().argv
const languageFilter = !args.languages
? () => true
: (langSpec: spec.LanguageSpec) =>
: (langSpec: LanguageSpec) =>
args.languages
.split(',')
.includes(langSpec.handlerArgs.languageID)
Expand All @@ -52,7 +50,7 @@ function main(): void {
shell.cp('-R', 'template/node_modules', 'temp/node_modules')
shell.cd('temp')

for (const langSpec of spec.languages.filter(languageFilter)) {
for (const langSpec of languageSpecs.filter(languageFilter)) {
const languageID = langSpec.handlerArgs.languageID
const stylized = langSpec.stylized
if (doNotGenerate.includes(languageID)) {
Expand Down Expand Up @@ -143,14 +141,11 @@ function main(): void {
'src/extension.ts'
)

fs.writeFileSync(
'src/extension.ts',
`import { activateBasicCodeIntel } from '@sourcegraph/basic-code-intel'

export const activate = activateBasicCodeIntel(${tosource.default(
langSpec.handlerArgs
)})
`
shell.sed(
'-i',
/const languageID = 'all'/,
`const languageID = '${languageID}'`,
'src/extension.ts'
)

shell.exec(
Expand Down
2 changes: 1 addition & 1 deletion languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const lispStyle: CommentStyle = {
// The set of languages come from https://madnight.github.io/githut/#/pull_requests/2018/4
// The language names come from https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers
// The extensions come from shared/src/languages.ts
export const languages: LanguageSpec[] = [
export const languageSpecs: LanguageSpec[] = [
{
handlerArgs: {
languageID: 'typescript',
Expand Down
17 changes: 14 additions & 3 deletions template/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { activateBasicCodeIntel } from '../../package/lib'
import * as sourcegraph from 'sourcegraph'
import * as spec from '../../languages'
import { languageSpecs } from '../../languages'

export function activate(ctx: sourcegraph.ExtensionContext): void {
for (const language of spec.languages) {
activateBasicCodeIntel(language.handlerArgs)(ctx)
// This is set to an individual language ID by the generator script.
const languageID = 'all'

if (languageID === 'all') {
for (const languageSpec of languageSpecs) {
activateBasicCodeIntel(languageSpec.handlerArgs)(ctx)
}
} else {
// TODO consider Record<LanguageID, LanguageSpec>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's preventing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time

activateBasicCodeIntel(
languageSpecs.find(l => l.handlerArgs.languageID === languageID)!
.handlerArgs
)(ctx)
}
}