Skip to content

Commit

Permalink
Merge pull request #85 from a793181018/NewMaster
Browse files Browse the repository at this point in the history
[new add chat pormpt data]:Customize project framework code files as contextNew master
  • Loading branch information
phodal authored Aug 30, 2024
2 parents 89ff89e + a52db83 commit 2548761
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 36 deletions.
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,19 @@
}
},
"order": 9
},
{
"title": "%autodev.WorkSpeace.customFrameworkCodeFiles.title%",
"properties": {
"autodev.WorkSpeace.customFrameworkCodeFiles": {
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "%autodev.WorkSpeace.customFrameworkCodeFiles.description%"
}
}
}
],
"commands": [
Expand All @@ -650,7 +663,6 @@
"command": "autodev.codelens.methodCompletions",
"title": "%command.AutoMethod.title%"
},

{
"command": "autodev.codelens.autoTest",
"title": "%command.autoTest.title%"
Expand Down
4 changes: 3 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,7 @@
"configuration.codelensDisplayMode.item.expand": "Expand",
"configuration.codelensDisplayMode.item.collapse": "Collapse",
"configuration.codelensDisplayMode.description": "Controls the display of CodeLens",
"configuration.codelensDisplayItems.description": "Custom the display and sorting CodeLens Items"
"configuration.codelensDisplayItems.description": "Custom the display and sorting CodeLens Items",
"autodev.WorkSpeace.customFrameworkCodeFiles.title":"Custom project framework context code files",
"autodev.WorkSpeace.customFrameworkCodeFiles.description":"Custom project framework context code files"
}
4 changes: 3 additions & 1 deletion package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,7 @@
"command.genApiData.title": "生成 API 数据",

"command.codebase.createIndexes.title": "索引生成",
"command.codebase.retrievalCode.title": "代码检索"
"command.codebase.retrievalCode.title": "代码检索",
"autodev.WorkSpeace.customFrameworkCodeFiles.title":"自定义项目框架上下文代码文件组",
"autodev.WorkSpeace.customFrameworkCodeFiles.description":"提示:自定义项目框架上下文代码文件组"
}
21 changes: 20 additions & 1 deletion src/action/autoMethod/AutoMethodActionExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { PromptManager } from '../../prompt-manage/PromptManager';
import { CreateToolchainContext } from '../../toolchain-context/ToolchainContextProvider';
import { ActionExecutor } from '../_base/ActionExecutor';
import { AutoMethodTemplateContext } from './AutoMethodTemplateContext';

import fs from 'fs'
import vscode from 'vscode';
export class AutoMethodActionExecutor implements ActionExecutor {
type: ActionType = ActionType.AutoDoc;

Expand Down Expand Up @@ -48,6 +49,23 @@ export class AutoMethodActionExecutor implements ActionExecutor {
const startSymbol = LANGUAGE_BLOCK_COMMENT_MAP[language]!.start;
const endSymbol = LANGUAGE_BLOCK_COMMENT_MAP[language]!.end;

const config=vscode.workspace.getConfiguration('autodev.WorkSpeace');
const customFrameworkCodeFilesPath=config.get<string[]>('customFrameworkCodeFiles', []);
let customFrameworkCodeFileContext:string="";
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) {
const workspaceFolder = vscode.workspace.workspaceFolders[0];
const workspacePath = workspaceFolder.uri.fsPath;
if(customFrameworkCodeFilesPath.length>0)
{ for(let i=0;i<customFrameworkCodeFilesPath.length;i++)
{
let codeFileNormalPath=workspacePath+'\\'+customFrameworkCodeFilesPath[i];
customFrameworkCodeFileContext+=fs.readFileSync(codeFileNormalPath).toString();
customFrameworkCodeFileContext+='\n'
}
}
}


const templateContext: AutoMethodTemplateContext = {
language: language,
startSymbol: startSymbol,
Expand All @@ -56,6 +74,7 @@ export class AutoMethodActionExecutor implements ActionExecutor {
forbiddenRules: [],
// 原有代码块
originalMethodCodes: [],
customFrameworkCodeFileContext
};

if (range.commentRange) {
Expand Down
1 change: 1 addition & 0 deletions src/action/autoMethod/AutoMethodTemplateContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export interface AutoMethodTemplateContext extends TemplateContext {
code: string;
forbiddenRules: string[];
originalMethodCodes: string[];
customFrameworkCodeFileContext?:string;
}
38 changes: 6 additions & 32 deletions src/code-context/csharp/CsharpProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export class CsharpProfile implements LanguageProfile {
(method_declaration
name: (identifier) @name.definition.method) @definition.method
`);
/**
* (struct_declaration
name: (identifier) @definition.struct)
*/
classQuery = new MemoizedQuery(`
(class_declaration
name: (identifier) @name.definition.class) @definition.class
Expand All @@ -32,38 +36,8 @@ export class CsharpProfile implements LanguageProfile {
(scoped_identifier) @package-name)
`);
structureQuery = new MemoizedQuery(`
(package_declaration
(scoped_identifier) @package-name)
(import_declaration
(scoped_identifier) @import-name)
(method_declaration
type: (_) @method-returnType
name: (identifier) @method-name
parameters: (formal_parameters
(formal_parameter
(type_identifier) @method-param.type
(identifier) @method-param.value
)?
@method-params)
body: (block) @method-body
)
(program
(class_declaration
name: ((identifier) @class-name)
interfaces: (super_interfaces (type_list (type_identifier) @impl-name))?
body:
(class_body
(field_declaration
(modifiers) @field-modifiers
(type_identifier) @field-type
(variable_declarator) @field-decl
)?
)
)
)
(struct_declaration
name: (identifier) @name.definition.struct) @definition.struct
`);
methodIOQuery = new MemoizedQuery(`
(method_declaration
Expand Down

0 comments on commit 2548761

Please sign in to comment.