Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
444b0f4
Update README.md to introduce functorcoder AI coding assistant and ou…
doofin Feb 6, 2025
e48e851
Update README.md to include project structure and bash commands for s…
doofin Feb 7, 2025
39a08ef
Add initial implementation of core components and configuration for f…
doofin Feb 10, 2025
7c5aec7
Refactor code to improve clarity by updating comments and removing un…
doofin Feb 10, 2025
50e336d
Update README.md to clarify project structure and features; modify pa…
doofin Feb 10, 2025
ae074a7
Implement command registration and status bar integration for functor…
doofin Feb 12, 2025
f2b62ad
Add GitHub Actions workflow for building and publishing VSIX package
doofin Feb 12, 2025
08d83db
Update GitHub Actions workflow and build configuration for debugging
doofin Feb 12, 2025
2d9435e
Enhance GitHub Actions workflow for packaging and uploading VSIX; upd…
doofin Feb 12, 2025
20bd9b7
Fix workflow script to chain commands for packaging extension in GitH…
doofin Feb 12, 2025
801f8e1
Update GitHub Actions workflow to trigger on release branch and impro…
doofin Feb 12, 2025
f096685
Comment out branch trigger in GitHub Actions workflow for release
doofin Feb 12, 2025
3f45ac8
Refactor GitHub Actions workflows and update configuration handling i…
doofin Feb 12, 2025
e2bd430
Enhance VSCode extension with inline editing capabilities and LLM int…
doofin Feb 15, 2025
4156e15
Refactor command handling to improve documentation generation; add la…
doofin Feb 16, 2025
032c170
Refactor command registration and improve command handling; replace c…
doofin Feb 17, 2025
283dde4
Remove unused imports and streamline code in LLM and VSCode extension…
doofin Feb 17, 2025
486f4b1
Enhance VSCode extension configuration by adding maxTokens parameter;…
doofin Feb 18, 2025
025beb4
Refactor build configuration and remove CodeActionProvider; add Inlin…
doofin Feb 19, 2025
1c9494b
Add file and folder creation functionality; implement tree parsing an…
doofin Mar 3, 2025
8209e38
Refactor command registration to include createFiles command; update …
doofin Mar 4, 2025
52105b8
Enhance status bar functionality by adding spinning status indicators…
doofin Mar 29, 2025
019fe5c
Update README for clarity on features and current status; change comm…
doofin Mar 30, 2025
7bcd295
Refactor build configuration and enhance logging; add printlnOrange f…
doofin Apr 1, 2025
b92d8f5
Refactor build script and improve logging; update VSCode task handlin…
doofin Apr 1, 2025
7324125
Refactor command structure and implement a new menu system; remove de…
doofin Apr 1, 2025
174509d
Refactor command names for consistency; update input box titles and i…
doofin Apr 2, 2025
dfff270
Refactor command handling to integrate llmAgent; update menu display …
doofin Apr 6, 2025
1d42270
Refactor create files command to streamline input handling; update ma…
doofin Apr 8, 2025
fd07593
parentPaths for create files
doofin Apr 9, 2025
741f071
createFiles show file list ok
doofin Apr 10, 2025
f61889f
Enhance LLM integration by adding model specification and refactoring…
doofin Apr 11, 2025
6890693
Refactor configuration handling by replacing settings with vscConfig;…
doofin Apr 11, 2025
fe08ca4
Refactor code completion and documentation handling; remove obsolete …
doofin Apr 11, 2025
7b2ba2b
Remove unused imports and clean up code in editorUI and extensionMain
doofin Apr 11, 2025
657a968
Add .sbtopts to .gitignore to exclude build options from version control
doofin Apr 15, 2025
6b36782
Update README to include RAG feature for enhanced code base understan…
doofin Apr 15, 2025
f307bd5
Update README to include MCP feature for environment interaction
doofin Apr 15, 2025
84cfe72
Update README for clarity and structure; modify prompt placeholders i…
doofin Apr 16, 2025
9c07d67
Merge branch 'dev2502' of github.com:doofin/functorcoder into dev2502
doofin Apr 16, 2025
fcdc8dd
Update README for improved clarity and add getting started section
doofin Apr 18, 2025
91f6327
better prompt
doofin Apr 19, 2025
456fc24
Refactor prompt class to use ctrlMsg instead of assistantMsg; update …
doofin Apr 19, 2025
d30fefe
Remove outdated OpenAI API request example from openaiReq.scala and c…
doofin Apr 20, 2025
25a7677
Add OpenAI API configuration example to README and clarify getting st…
doofin Apr 20, 2025
7fd4b21
Update README to enhance clarity and detail current features and gett…
doofin Apr 20, 2025
3c53c64
Update README to include next important features and add a Chinese in…
doofin Apr 21, 2025
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
61 changes: 61 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Release

# trigger on git push for release branch
on:
workflow_dispatch: # allow manual trigger
push:
branches:
- release

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
run:
name: Build and publish vsix package
strategy:
matrix:
java-version: [17]
runs-on: ubuntu-latest
steps:
- name: Checkout current branch
uses: actions/checkout@v4
with:
fetch-depth: 0
# cache sbt dependencies
- uses: coursier/cache-action@v6

# install java, sbt and node
- name: Setup Java and sbt
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ matrix.java-version }}
cache: sbt
- uses: sbt/setup-sbt@v1

- name: setup node
uses: actions/setup-node@v4

# install dependencies and build package
- name: compile Scala and build js to out/ folder
run:
sbt buildDebug

- name: package extension inside out/ folder
run: |
cd out/
ls -la
npx vsce package

- name: Get upload url
id: get_upload_url
run: |
URL=$(curl --silent "https://api.github.com/repos/doofin/functorcoder/releases/latest" | jq -r '.upload_url')
echo ::set-output name=UPLOAD_URL::$URL

- name: Upload VSIX package to github release
uses: softprops/action-gh-release@v2
# if: startsWith(github.ref, 'refs/tags/')
with:
files: out/functorcoder-0.0.1.vsix
7 changes: 5 additions & 2 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Continuous Integration
name: CI

on:
push:
Expand All @@ -8,7 +8,7 @@ env:

jobs:
run:
name: Build and Run
name: Compile
strategy:
matrix:
java-version: [17]
Expand All @@ -26,6 +26,9 @@ jobs:
java-version: ${{ matrix.java-version }}
cache: sbt

# cache sbt dependencies
- uses: coursier/cache-action@v6

- uses: sbt/setup-sbt@v1

- name: compile
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ out
/project/target/
/.bsp/

*.worksheet.sc
.sbtopts
163 changes: 83 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,112 @@
# VSCode Extension in Scala.js
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.
# functorcoder
**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.

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

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

features aiming to implement in long term:
- code generation: completion, documentation
- code modification: refactoring, optimization, bug fixing
- code analysis: code understanding, code review, code quality

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

* 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):
```bash
sbt open
```
所以,作为一个scala的爱好者,也希望加深对llm应用的理解,我决定自己用scala.js来实现一个简单的ai助手。

After the new VSCode (extension development host) window opens:
* Run the Hello World command from the Command Palette (`⇧⌘P`) in the new VSCode window.
* Type `hello` and select `Hello World`.
* You should see a Notification _Hello World!_.
## Getting Started
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:
- setting up the development environment
- building the project and running the extension
- packaging the extension


### Use it as a template
click on the `Use this template` button to create a new repository with the same structure in github.
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:

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

### Use it as a library
**Currently not working** due to jitpack missing npm! Welcome to contribute to fix it.
## Project Structure
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.

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

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

Note:
- I recommend using the Metals extension for Scala in VSCode.
- If you have any issues, please open an issue on this repository.
The second part is the VSCode extension module, which integrates the core module with the VSCode editor. It contains:
- commands: commands to be executed in the editor
- code actions: quick fix actions
- code completion: auto completion
- editor ui: status bar, notifications, etc.

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.

## Project structure
The project file structure in src/main/scala is as follows:

project file structure for the core module:
```bash
src/main/scala
├── extensionMain.scala // main entry point for the extension
├── commands.scala, codeActions.scala,etc // files for different extension features
│   ├── facade // facade for vscode api
│   ├── io // file and network io functions
/functorcoder
├── /src/main/scala/functorcoder
│ ├── /llm # Integration with LLM (e.g., OpenAI API)
│ ├── /actions
│ │ ├── CodeGen.scala # Code completion, generation, and documentation
│ │ ├── Commands.scala # Commands from functorcoder
│ │ └── Debug.scala # Debugging module
│ ├── /types # Types for code, context, and user actions
│ ├── /editorUI # Integration with the editor (e.g., VSCode)
│ └── /tests # Unit tests for core modules
└── /docs # Documentation
```

The project file structure for the VSCode extension module:
```bash
/vscextension
├── /src/main/scala/vscextension
│ ├── extensionMain.scala # Main entry point for the extension
│ ├── commands.scala # Command definitions
│ ├── codeActions.scala # Code action definitions
...
```

The project uses the following tools:
* [SBT] build tool for building the project
* [Scala.js] for general coding
* [Scalably Typed] for JavaScript facades
* [scalajs-bundler] for bundling the JavaScript dependencies

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`.

[accessible-scala]: https://marketplace.visualstudio.com/items?itemName=scala-center.accessible-scala
[helloworld-minimal-sample]: https://github.com/Microsoft/vscode-extension-samples/tree/master/helloworld-minimal-sample
[Scalably Typed]: https://github.com/ScalablyTyped/Converter
[SBT]: https://www.scala-sbt.org
[ScalaJS]: http://www.scala-js.org
[scalajs-bundler]: https://github.com/scalacenter/scalajs-bundler

## How to code in Scala js?
## design principles
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.

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

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

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

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

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

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

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