Skip to content

Commit

Permalink
Fix provider implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tinvaan committed May 27, 2024
1 parent 8f91bf6 commit 4b7a1c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
50 changes: 24 additions & 26 deletions provider/techstack/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

import fs from 'fs'
import YAML from 'yaml'
import {
type AnnotationsParams,
type AnnotationsResult,
type CapabilitiesParams,
type CapabilitiesResult,
type Item,
type Provider
} from '@opencodegraph/provider'
import type {
AnnotationsParams,
AnnotationsResult,
MetaParams,
MetaResult,
Provider,
Annotation
} from '@openctx/provider'

import type TSF from './techstack.schema'
export interface Settings { yaml: string }
import type TSF from './techstack.schema.ts'
export type Settings = { yaml: string }

/**
* Read the techstack file configuration for project
Expand All @@ -37,13 +37,16 @@ async function load(fileUri: string): Promise<TSF> {
}

const techstack: Provider<Settings> = {
capabilities(params: CapabilitiesParams, settings: Settings): CapabilitiesResult {
// TODO: support more languages
return { selector: [{ path: '**/*.js?(x)' }, { path: '**/*.ts?(x)' }] }
meta(params: MetaParams, settings: Settings): MetaResult {
return {
name: 'TechStack File',
selector: [{ path: '**/*.js?(x)' }, { path: '**/*.ts?(x)' }],
features: { mentions: false }
}
},

async annotations(params: AnnotationsParams, settings: Settings): Promise<AnnotationsResult> {
const result: AnnotationsResult = { items: [], annotations: [] }
const anns: Annotation[] = []
const regex = /\b(?:import\s*[\w{},\s]+|require\s*\([^)]+\))\s*/g

if (settings.yaml !== null) {
Expand All @@ -57,22 +60,17 @@ const techstack: Provider<Settings> = {
targets.forEach((line, index) => {
if (line !== null) {
const target = Object.values(line as object).pop()
const linenum = Object.keys(line as object).pop()
const tool = pkgs.find(p => target.includes(p.name))
if (tool !== undefined) {
const item: Item = {
id: linenum?.toString() || '-1',
title: `📖 Techstack: ${tool.sub_category}`,
url: tool.website_url ?? tool.package_url
}

// Populate results
result.items.push(item)
result.annotations.push({
item: { id: item.id },
anns.push({
uri: params.uri,
range: {
start: { line: index, character: 0 },
end: { line: index, character: 1 }
},
item: {
title: `📖 Techstack: ${tool.sub_category}`,
url: tool.website_url ?? tool.package_url
}
})
}
Expand All @@ -81,7 +79,7 @@ const techstack: Provider<Settings> = {
}
}

return result
return anns
},
}

Expand Down
1 change: 0 additions & 1 deletion provider/techstack/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../.config/tsconfig.base.json",
"compilerOptions": {
"module": "ESNext",
"rootDir": ".",
"outDir": "dist",
"lib": ["ESNext", "DOM"],
Expand Down

0 comments on commit 4b7a1c6

Please sign in to comment.