Skip to content

Commit 4b7a1c6

Browse files
committed
Fix provider implementation
1 parent 8f91bf6 commit 4b7a1c6

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

provider/techstack/index.ts

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11

22
import fs from 'fs'
33
import YAML from 'yaml'
4-
import {
5-
type AnnotationsParams,
6-
type AnnotationsResult,
7-
type CapabilitiesParams,
8-
type CapabilitiesResult,
9-
type Item,
10-
type Provider
11-
} from '@opencodegraph/provider'
4+
import type {
5+
AnnotationsParams,
6+
AnnotationsResult,
7+
MetaParams,
8+
MetaResult,
9+
Provider,
10+
Annotation
11+
} from '@openctx/provider'
1212

13-
import type TSF from './techstack.schema'
14-
export interface Settings { yaml: string }
13+
import type TSF from './techstack.schema.ts'
14+
export type Settings = { yaml: string }
1515

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

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

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

4952
if (settings.yaml !== null) {
@@ -57,22 +60,17 @@ const techstack: Provider<Settings> = {
5760
targets.forEach((line, index) => {
5861
if (line !== null) {
5962
const target = Object.values(line as object).pop()
60-
const linenum = Object.keys(line as object).pop()
6163
const tool = pkgs.find(p => target.includes(p.name))
6264
if (tool !== undefined) {
63-
const item: Item = {
64-
id: linenum?.toString() || '-1',
65-
title: `📖 Techstack: ${tool.sub_category}`,
66-
url: tool.website_url ?? tool.package_url
67-
}
68-
69-
// Populate results
70-
result.items.push(item)
71-
result.annotations.push({
72-
item: { id: item.id },
65+
anns.push({
66+
uri: params.uri,
7367
range: {
7468
start: { line: index, character: 0 },
7569
end: { line: index, character: 1 }
70+
},
71+
item: {
72+
title: `📖 Techstack: ${tool.sub_category}`,
73+
url: tool.website_url ?? tool.package_url
7674
}
7775
})
7876
}
@@ -81,7 +79,7 @@ const techstack: Provider<Settings> = {
8179
}
8280
}
8381

84-
return result
82+
return anns
8583
},
8684
}
8785

provider/techstack/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"extends": "../../.config/tsconfig.base.json",
33
"compilerOptions": {
4-
"module": "ESNext",
54
"rootDir": ".",
65
"outDir": "dist",
76
"lib": ["ESNext", "DOM"],

0 commit comments

Comments
 (0)