Skip to content

Commit aaf2ee4

Browse files
authored
init:auto completion and add documentation code action (#1)
* Update README.md to introduce functorcoder AI coding assistant and outline project features and structure * Update README.md to include project structure and bash commands for setup * Add initial implementation of core components and configuration for functorcoder * Refactor code to improve clarity by updating comments and removing unused imports * Update README.md to clarify project structure and features; modify package.json for proper naming and description; enhance editorConfig.scala for improved parameter clarity * Implement command registration and status bar integration for functorcoder; add command actions and quick pick functionality * Add GitHub Actions workflow for building and publishing VSIX package * Update GitHub Actions workflow and build configuration for debugging * Enhance GitHub Actions workflow for packaging and uploading VSIX; update package.json to include repository information * Fix workflow script to chain commands for packaging extension in GitHub Actions * Update GitHub Actions workflow to trigger on release branch and improve VSIX upload process * Comment out branch trigger in GitHub Actions workflow for release * Refactor GitHub Actions workflows and update configuration handling in the extension * Enhance VSCode extension with inline editing capabilities and LLM integration; refactor code structure and improve configuration handling * Refactor command handling to improve documentation generation; add language detection and streamline code action prompts * Refactor command registration and improve command handling; replace command definitions with tuples and create vscCommands object for command registration * Remove unused imports and streamline code in LLM and VSCode extension files * Enhance VSCode extension configuration by adding maxTokens parameter; refactor command handling and improve code structure for better maintainability * Refactor build configuration and remove CodeActionProvider; add InlineEdit functionality for enhanced user interaction * Add file and folder creation functionality; implement tree parsing and enhance prompt handling * Refactor command registration to include createFiles command; update build command alias and enhance quick pick functionality for file generation * Enhance status bar functionality by adding spinning status indicators during loading; update README for clarity * Update README for clarity on features and current status; change command references in package.json to 'functorcoder.menu' * Refactor build configuration and enhance logging; add printlnOrange function for colored output and improve status bar messaging with language context * Refactor build script and improve logging; update VSCode task handling and enhance status bar messaging * Refactor command structure and implement a new menu system; remove deprecated main menu items and enhance quick pick functionality * Refactor command names for consistency; update input box titles and improve quick pick functionality * Refactor command handling to integrate llmAgent; update menu display and status bar item creation * Refactor create files command to streamline input handling; update main menu to invoke command directly and enhance quick pick functionality * parentPaths for create files * createFiles show file list ok * Enhance LLM integration by adding model specification and refactoring code completion logic; update README with upcoming features * Refactor configuration handling by replacing settings with vscConfig; update model default to use openaiReq; add .worksheet.sc to .gitignore * Refactor code completion and documentation handling; remove obsolete CodeCompletion and editorCtx files, and introduce CodeGen for improved functionality * Remove unused imports and clean up code in editorUI and extensionMain * Add .sbtopts to .gitignore to exclude build options from version control * Update README to include RAG feature for enhanced code base understanding * Update README to include MCP feature for environment interaction * Update README for clarity and structure; modify prompt placeholders in llmPrompt; adjust logging in inlineCompletions; add comments in createFiles * Update README for improved clarity and add getting started section * better prompt * Refactor prompt class to use ctrlMsg instead of assistantMsg; update configuration keys for API settings * Remove outdated OpenAI API request example from openaiReq.scala and clean up comments * Add OpenAI API configuration example to README and clarify getting started instructions * Update README to enhance clarity and detail current features and getting started instructions * Update README to include next important features and add a Chinese introduction
1 parent c540152 commit aaf2ee4

30 files changed

+1672
-315
lines changed

.github/workflows/publish.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Release
2+
3+
# trigger on git push for release branch
4+
on:
5+
workflow_dispatch: # allow manual trigger
6+
push:
7+
branches:
8+
- release
9+
10+
env:
11+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12+
13+
jobs:
14+
run:
15+
name: Build and publish vsix package
16+
strategy:
17+
matrix:
18+
java-version: [17]
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout current branch
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
# cache sbt dependencies
26+
- uses: coursier/cache-action@v6
27+
28+
# install java, sbt and node
29+
- name: Setup Java and sbt
30+
uses: actions/setup-java@v4
31+
with:
32+
distribution: temurin
33+
java-version: ${{ matrix.java-version }}
34+
cache: sbt
35+
- uses: sbt/setup-sbt@v1
36+
37+
- name: setup node
38+
uses: actions/setup-node@v4
39+
40+
# install dependencies and build package
41+
- name: compile Scala and build js to out/ folder
42+
run:
43+
sbt buildDebug
44+
45+
- name: package extension inside out/ folder
46+
run: |
47+
cd out/
48+
ls -la
49+
npx vsce package
50+
51+
- name: Get upload url
52+
id: get_upload_url
53+
run: |
54+
URL=$(curl --silent "https://api.github.com/repos/doofin/functorcoder/releases/latest" | jq -r '.upload_url')
55+
echo ::set-output name=UPLOAD_URL::$URL
56+
57+
- name: Upload VSIX package to github release
58+
uses: softprops/action-gh-release@v2
59+
# if: startsWith(github.ref, 'refs/tags/')
60+
with:
61+
files: out/functorcoder-0.0.1.vsix

.github/workflows/scala.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Continuous Integration
1+
name: CI
22

33
on:
44
push:
@@ -8,7 +8,7 @@ env:
88

99
jobs:
1010
run:
11-
name: Build and Run
11+
name: Compile
1212
strategy:
1313
matrix:
1414
java-version: [17]
@@ -26,6 +26,9 @@ jobs:
2626
java-version: ${{ matrix.java-version }}
2727
cache: sbt
2828

29+
# cache sbt dependencies
30+
- uses: coursier/cache-action@v6
31+
2932
- uses: sbt/setup-sbt@v1
3033

3134
- name: compile

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ out
3838
/project/target/
3939
/.bsp/
4040

41+
*.worksheet.sc
42+
.sbtopts

README.md

Lines changed: 83 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,112 @@
1-
# VSCode Extension in Scala.js
2-
Write vscode extensions in Scala.js! This is a collection of examples and templates to get you started, with convenient sbt tasks to build and run your extension.
1+
# functorcoder
2+
**functorcoder** is an open source AI coding assistant utilizing LLM (Large Language Model) with algebraic and modular design in Scala.js. It aims at providing a clean and extensible architecture for AI coding assistants, which is helpful for understanding basic mechanics if you want to build your own AI coding assistant.
33

4-
contains:
5-
- commands from the vscode command palette
6-
- inline completion like github copilot
7-
- language server protocol client
8-
- code actions (when pressing Alt+Enter at a code location)
4+
current features implemented:
5+
- auto completion as you type
6+
- add documentation quick fix action
97

10-
### Setup
11-
Requirements:
12-
- [Sbt](https://www.scala-sbt.org/download.html)
8+
next important features to be implemented:
9+
- generate multiple files and folders
10+
- disable/enable auto completion
1311

12+
features aiming to implement in long term:
13+
- code generation: completion, documentation
14+
- code modification: refactoring, optimization, bug fixing
15+
- code analysis: code understanding, code review, code quality
1416

15-
Run the vscode extension:
16-
* Clone this project
17-
* Open the project in VSCode, run the `import build` task with Metals (it should display a popup automatically).
17+
## 中文简介
18+
作为一个copilot的用户,最近受到国产开源模型deepseek的鼓励,希望能在开源社区中贡献一些自己的力量。目前已经有一些ai插件,比如copilot, tabnine,cursor等,还有一些开源的插件,比如continue。我看了下continue的代码,发现它的设计很复杂,代码并不简洁。目前,copilot的体验还可以,但是非常封闭,无法自定义很多地方,比如代码补全的长度,模型的选择等。开源的插件则有很多稳定性问题,bug不少。
1819

19-
* run below command, which will open a new VSCode window with the extension loaded(first time it will take some time for scalable typed to convert typescript to scala.js):
20-
```bash
21-
sbt open
22-
```
20+
所以,作为一个scala的爱好者,也希望加深对llm应用的理解,我决定自己用scala.js来实现一个简单的ai助手。
2321

24-
After the new VSCode (extension development host) window opens:
25-
* Run the Hello World command from the Command Palette (`⇧⌘P`) in the new VSCode window.
26-
* Type `hello` and select `Hello World`.
27-
* You should see a Notification _Hello World!_.
22+
## Getting Started
23+
Visit [vscode-scalajs-hello](https://github.com/doofin/vscode-scalajs-hello) to understand how to play with scala.js for VSCode extension development. Basically, sbt is used to build the project and run the extension. There you will learn:
24+
- setting up the development environment
25+
- building the project and running the extension
26+
- packaging the extension
2827

2928

30-
### Use it as a template
31-
click on the `Use this template` button to create a new repository with the same structure in github.
29+
Before loading the extension, you need to add options to vscode user settings, and provide your OpenAI compatible API key and URL. Here is an example:
3230

33-
### Use it as sbt dependency
34-
In your `build.sbt` add the following:
35-
```scala
36-
lazy val vsc = RootProject(uri("https://github.com/doofin/vscode-scalajs-hello.git"))
37-
lazy val root = Project("root", file(".")) dependsOn(vsc)
31+
```json
32+
"functorcoder": {
33+
"apiKey": "somekey",
34+
"apiUrl": "https://api.openai.com/v1/chat/completions",
35+
"maxTokens": 512,
36+
"model": "gpt-4o-mini",
37+
}
3838
```
3939

40-
### Use it as a library
41-
**Currently not working** due to jitpack missing npm! Welcome to contribute to fix it.
40+
## Project Structure
41+
The project is divided into two main parts: the core module and the VSCode extension module under /src/main/scala/functorcoder and /src/main/scala/vscextension respectively.
4242

43-
You can use this project as a library in your project by adding the following to your `build.sbt`:
44-
```scala
45-
resolvers += Resolver.bintrayRepo("jitpack", "https://jitpack.io")
46-
libraryDependencies += "com.github.doofin" % "vscode-scalajs-hello" % "master-SNAPSHOT" // might be wrong
47-
```
43+
**To get started**, read the file `extensionMain.scala` in the VSCode extension module. It is the main entry point for the extension.
4844

49-
You can find the latest version on
50-
[jitpack.](https://jitpack.io/#doofin/vscode-scalajs-hello)
45+
The first part is the core module, we aim keeping it concise. It contains the main logic of the ai coding assistant:
46+
- Large Language Model (LLM) integration
47+
- sending propmt to LLM and getting the response
5148

52-
Note:
53-
- I recommend using the Metals extension for Scala in VSCode.
54-
- If you have any issues, please open an issue on this repository.
49+
The second part is the VSCode extension module, which integrates the core module with the VSCode editor. It contains:
50+
- commands: commands to be executed in the editor
51+
- code actions: quick fix actions
52+
- code completion: auto completion
53+
- editor ui: status bar, notifications, etc.
54+
55+
It's adopted from the [vscode-scalajs-hello](https://github.com/doofin/vscode-scalajs-hello) project. Refer to it for getting started with the VSCode extension development in Scala.js.
5556

56-
## Project structure
57-
The project file structure in src/main/scala is as follows:
57+
58+
project file structure for the core module:
5859
```bash
59-
src/main/scala
60-
├── extensionMain.scala // main entry point for the extension
61-
├── commands.scala, codeActions.scala,etc // files for different extension features
62-
│   ├── facade // facade for vscode api
63-
│   ├── io // file and network io functions
60+
/functorcoder
61+
├── /src/main/scala/functorcoder
62+
│ ├── /llm # Integration with LLM (e.g., OpenAI API)
63+
│ ├── /actions
64+
│ │ ├── CodeGen.scala # Code completion, generation, and documentation
65+
│ │ ├── Commands.scala # Commands from functorcoder
66+
│ │ └── Debug.scala # Debugging module
67+
│ ├── /types # Types for code, context, and user actions
68+
│ ├── /editorUI # Integration with the editor (e.g., VSCode)
69+
│ └── /tests # Unit tests for core modules
70+
└── /docs # Documentation
6471
```
6572

73+
The project file structure for the VSCode extension module:
74+
```bash
75+
/vscextension
76+
├── /src/main/scala/vscextension
77+
│ ├── extensionMain.scala # Main entry point for the extension
78+
│ ├── commands.scala # Command definitions
79+
│ ├── codeActions.scala # Code action definitions
80+
...
81+
```
6682

67-
The project uses the following tools:
68-
* [SBT] build tool for building the project
69-
* [Scala.js] for general coding
70-
* [Scalably Typed] for JavaScript facades
71-
* [scalajs-bundler] for bundling the JavaScript dependencies
72-
73-
SBT is configured with the `build.sbt` file. Scala.js, ScalablyTyped and the bundler are SBT plugins. With these, SBT manages your JavaScript `npm` dependencies. You should never have to run `npm` directly, simply edit the `npmDependencies` settings in `build.sbt`.
74-
75-
[accessible-scala]: https://marketplace.visualstudio.com/items?itemName=scala-center.accessible-scala
76-
[helloworld-minimal-sample]: https://github.com/Microsoft/vscode-extension-samples/tree/master/helloworld-minimal-sample
77-
[Scalably Typed]: https://github.com/ScalablyTyped/Converter
78-
[SBT]: https://www.scala-sbt.org
79-
[ScalaJS]: http://www.scala-js.org
80-
[scalajs-bundler]: https://github.com/scalacenter/scalajs-bundler
8183

82-
## How to code in Scala js?
84+
## design principles
85+
I am to design the system with mathematics, algebra and functional programming principles in mind. The system is designed to be modular and extensible, allowing for easy addition of new features and components.
8386

84-
In general, javascript functions and classes can be used in the same way as in JS/TS!
85-
If the typechecker disagrees, you can insert casts with `.asInstanceOf[Type]`.
87+
Input = {Query, CodeSnippet, Spec}: The set of all possible input types (queries, code snippets, or requirements/specifications).
8688

87-
The JS types (like `js.Array`) are available from
88-
```scala
89-
import scala.scalajs.js
90-
```
89+
Output = {Code, Explanation, Transformation, DebugSuggestion}: The set of all possible outputs.
9190

92-
The VSCode classes and functions are available from
93-
```scala
94-
import typings.vscode.mod as vscode
91+
The types and objects for Input:
92+
- code snippet or code file: a piece of code
93+
- code context: a code snippet with its surrounding code
94+
- query: natural language query
95+
- specification: natural language specification
9596

96-
vscode.window.showInformationMessage("Hello World!")
97-
```
97+
The Output:
98+
- code snippet or code file: a piece of code, including completion, refactoring, optimization, bug fixing
99+
- explanation: a natural language explanation
100+
- transformation: the transformation of the input code
101+
- suggestion: a suggestion for debugging or improvement or refactoring
98102

99-
Some additional types are available in the `anon` subpackage, for example:
100-
```scala
101-
import typings.vscode.anon.Dispose
102-
// register a command. The cast is necessary due to typescript conversion limitations.
103-
vscode.commands.registerCommand(name, fun).asInstanceOf[Dispose]
104-
```
103+
# feedback
104+
features to be implemented:
105+
- refactoring
106+
- specify which LLM to use
107+
- RAG(retrieval-augmented generation) to understand the whole code base
108+
- MCP(model context protocol) to interact with the environment, like external tools, etc.
105109

106-
You can find more information and tutorials on the [Scala.js website](https://www.scala-js.org/).
107110

108111
# references:
109112
- updated from [vscode-scalajs-hello](https://github.com/pme123/vscode-scalajs-hello) with Scala 3.3.3 and sbt.version=1.9.7.

0 commit comments

Comments
 (0)