Skip to content

Commit

Permalink
feat: migrate to new local AI setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dung Huynh Duc committed Jul 25, 2024
1 parent 506d3dc commit bb103e2
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 81 deletions.
113 changes: 61 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Update your settings.json file with the following configuration:
<!-- ALL-SETTINGS:START -->

```jsonc
// settings.json, generated at Wed Jul 24 2024 20:08:49 GMT+0800 (Singapore Standard Time)
// settings.json, generated at Thu Jul 25 2024 10:31:45 GMT+0800 (Singapore Standard Time)
// Zed settings
//
// For information on how to configure Zed, see the Zed
Expand All @@ -44,6 +44,7 @@ Update your settings.json file with the following configuration:
// custom settings, run the `open default settings` command
// from the command palette or from `Zed` application menu.
{
"base_keymap": "VSCode",
"theme": "Dracula",
"ui_font_size": 16,
"buffer_font_size": 18,
Expand All @@ -53,43 +54,49 @@ Update your settings.json file with the following configuration:
// use relative line numbers
"relative_line_numbers": true,
"tab_bar": {
"show": true,
"show": true
},
"scrollbar": {
"show": "never",
"show": "never"
},
// Indentation, rainbow indentation
"indent_guides": {
"enabled": true,
"coloring": "indent_aware",
"coloring": "indent_aware"
},
// NOTE: Zen mode, refer https://github.com/zed-industries/zed/issues/4382 when it's resolved
"centered_layout": {
"left_padding": 0.2,
"right_padding": 0.2,
"right_padding": 0.2
},
// Local AI with Ollama, refer https://zed.dev/docs/assistant-panel#using-ollama-on-macos
// Local AI with Ollama, refer https://zed.dev/docs/language-model-integration?highlight=ollama#using-ollama-on-macos
"assistant": {
"version": "1",
"provider": {
"name": "openai",
"type": "openai",
"default_model": "gpt-4-turbo-preview",
// make sure ollama is running
"api_url": "http://localhost:11434/v1",
},
"default_model": {
"name": "gpt-4-turbo-preview:latest",
"max_tokens": 2048,
"keep_alive": -1
},
"name": "ollama"
}
},
"language_models": {
"ollama": {
"api_url": "http://localhost:11434"
}
},
// Inlay hints preconfigured by Zed: Go, Rust, Typescript and Svelte
"inlay_hints": {
"enabled": true,
"enabled": true
},
// LSP
"lsp": {
"tailwindcss-language-server": {
"settings": {
"classAttributes": ["class", "className", "ngClass", "styles"],
},
},
"classAttributes": ["class", "className", "ngClass", "styles"]
}
}
},
"languages": {
// Refer https://zed.dev/docs/languages/javascript and https://zed.dev/docs/languages/typescript for more info
Expand All @@ -99,39 +106,40 @@ Update your settings.json file with the following configuration:
"enabled": true,
"show_parameter_hints": false,
"show_other_hints": true,
"show_type_hints": true,
},
},
"show_type_hints": true
}
}
},
// Use zed commit editor
"terminal": {
"env": {
"EDITOR": "zed --wait",
},
"EDITOR": "zed --wait"
}
},
// File syntax highlighting
"file_types": {
"Dockerfile": ["Dockerfile", "Dockerfile.*"],
"JSON": ["json", "jsonc", "*.code-snippets"],
"JSON": ["json", "jsonc", "*.code-snippets"]
},
// Turn off telemetry
"telemetry": {
"diagnostics": false,
"metrics": false,
"metrics": false
},
// Move all panel to the right
"project_panel": {
"button": true,
"dock": "right",
"git_status": true,
"git_status": true
},
"outline_panel": {
"dock": "right",
"dock": "right"
},
"collaboration_panel": {
"dock": "right",
},
"dock": "right"
}
}

```

<!-- ALL-SETTINGS:END -->
Expand All @@ -147,7 +155,7 @@ Update your keymap.json file with the following key bindings:
<!-- ALL-KEYMAPS:START -->

```jsonc
// keymap.json, generated at Wed Jul 24 2024 20:08:49 GMT+0800 (Singapore Standard Time)
// keymap.json, generated at Thu Jul 25 2024 10:31:45 GMT+0800 (Singapore Standard Time)
[
{
"context": "Editor && (vim_mode == normal || vim_mode == visual) && !VimWaiting && !menu",
Expand Down Expand Up @@ -175,8 +183,8 @@ Update your keymap.json file with the following key bindings:
// Search word under cursor
"space s w": "pane::DeploySearch",
// Go to file with `gf`
"g f": "editor::OpenExcerpts",
},
"g f": "editor::OpenExcerpts"
}
},
{
"context": "Editor && vim_mode == normal && !VimWaiting && !menu",
Expand Down Expand Up @@ -233,8 +241,8 @@ Update your keymap.json file with the following key bindings:
"space space": "file_finder::Toggle",
// TODO: Open other files
// Show project panel with current file
"space e": "pane::RevealInProjectPanel",
},
"space e": "pane::RevealInProjectPanel"
}
},
// Empty pane, set of keybindings that are available when there is no active editor
{
Expand All @@ -243,50 +251,50 @@ Update your keymap.json file with the following key bindings:
// Open file finder
"space space": "file_finder::Toggle",
// Open recent project
"space f p": "projects::OpenRecent",
},
"space f p": "projects::OpenRecent"
}
},
// Comment code
{
"context": "Editor && vim_mode == visual && !VimWaiting && !menu",
"bindings": {
// visual, visual line & visual block modes
"g c": "editor::ToggleComments",
},
"g c": "editor::ToggleComments"
}
},
// Better escape
{
"context": "Editor && vim_mode == insert && !menu",
"bindings": {
"j j": "vim::NormalBefore", // remap jj in insert mode to escape
},
"j j": "vim::NormalBefore" // remap jj in insert mode to escape
}
},
// Rename
{
"context": "Editor && vim_operator == c",
"bindings": {
"c": "vim::CurrentLine",
"r": "editor::Rename", // zed specific
},
"r": "editor::Rename" // zed specific
}
},
// Code Action
{
"context": "Editor && vim_operator == c",
"bindings": {
"c": "vim::CurrentLine",
"a": "editor::ToggleCodeActions", // zed specific
},
"a": "editor::ToggleCodeActions" // zed specific
}
},
// Toggle terminal
{
"context": "Workspace",
"bindings": {
"ctrl-\\": "terminal_panel::ToggleFocus",
},
"ctrl-\\": "terminal_panel::ToggleFocus"
}
},
{
"context": "Terminal",
"bindings": {},
"bindings": {}
},
// File panel (netrw)
{
Expand All @@ -301,8 +309,8 @@ Update your keymap.json file with the following key bindings:
"p": "project_panel::Paste",
// Close project panel as project file panel on the right
"q": "workspace::ToggleRightDock",
"space e": "workspace::ToggleRightDock",
},
"space e": "workspace::ToggleRightDock"
}
},
// Panel nagivation
{
Expand All @@ -311,16 +319,16 @@ Update your keymap.json file with the following key bindings:
"ctrl-w h": ["workspace::ActivatePaneInDirection", "Left"],
"ctrl-w l": ["workspace::ActivatePaneInDirection", "Right"],
"ctrl-w k": ["workspace::ActivatePaneInDirection", "Up"],
"ctrl-w j": ["workspace::ActivatePaneInDirection", "Down"],
},
"ctrl-w j": ["workspace::ActivatePaneInDirection", "Down"]
}
},
{
"context": "Workspace",
"bindings": {
// Map VSCode like keybindings
"cmd-b": "workspace::ToggleRightDock",
},
},
"cmd-b": "workspace::ToggleRightDock"
}
}
// Subword motion is not working really nice with `ciw`, disable for now
// {
// "context": "VimControl && !menu",
Expand All @@ -332,6 +340,7 @@ Update your keymap.json file with the following key bindings:
// }
// }
]

```

<!-- ALL-KEYMAPS:END -->
Expand Down
46 changes: 23 additions & 23 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import path from "node:path";
const filePath = path.join(__dirname, "README.md");

const readFileSync = (filePath: string) => {
if (!fs.existsSync(filePath)) {
throw new Error(`File ${filePath} does not exist.`);
}
return fs.readFileSync(filePath, "utf8");
if (!fs.existsSync(filePath)) {
throw new Error(`File ${filePath} does not exist.`);
}
return fs.readFileSync(filePath, "utf8");
};

const generateMarkdown = (fileName: string, data: string) => `
Expand All @@ -27,24 +27,24 @@ ${data}
`;

try {
const settings = readFileSync(path.join(__dirname, "settings.json"));
const keymap = readFileSync(path.join(__dirname, "keymap.json"));
const data = readFileSync(filePath);

const settingsMarkdown = generateMarkdown("settings.json", settings);
const keymapsMarkdown = generateMarkdown("keymap.json", keymap);

let result = data.replace(
/(<!-- ALL-SETTINGS:START -->)[\s\S]*?(<!-- ALL-SETTINGS:END -->)/gs,
`$1\n${settingsMarkdown}\n$2`,
);
result = result.replace(
/(<!-- ALL-KEYMAPS:START -->)[\s\S]*?(<!-- ALL-KEYMAPS:END -->)/gs,
`$1\n${keymapsMarkdown}\n$2`,
);

fs.writeFileSync(filePath, result);
console.log("Done");
const settings = readFileSync(path.join(__dirname, "settings.json"));
const keymap = readFileSync(path.join(__dirname, "keymap.json"));
const data = readFileSync(filePath);

const settingsMarkdown = generateMarkdown("settings.json", settings);
const keymapsMarkdown = generateMarkdown("keymap.json", keymap);

let result = data.replace(
/(<!-- ALL-SETTINGS:START -->)[\s\S]*?(<!-- ALL-SETTINGS:END -->)/gs,
`$1\n${settingsMarkdown}\n$2`,
);
result = result.replace(
/(<!-- ALL-KEYMAPS:START -->)[\s\S]*?(<!-- ALL-KEYMAPS:END -->)/gs,
`$1\n${keymapsMarkdown}\n$2`,
);

fs.writeFileSync(filePath, result);
console.log("Done");
} catch (error) {
console.error(new Error("An error occurred", { cause: error }));
console.error(new Error("An error occurred", { cause: error }));
}
19 changes: 13 additions & 6 deletions settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// custom settings, run the `open default settings` command
// from the command palette or from `Zed` application menu.
{
"base_keymap": "VSCode",
"theme": "Dracula",
"ui_font_size": 16,
"buffer_font_size": 18,
Expand All @@ -31,15 +32,21 @@
"left_padding": 0.2,
"right_padding": 0.2
},
// Local AI with Ollama, refer https://zed.dev/docs/assistant-panel#using-ollama-on-macos
// Local AI with Ollama, refer https://zed.dev/docs/language-model-integration?highlight=ollama#using-ollama-on-macos
"assistant": {
"version": "1",
"provider": {
"name": "openai",
"type": "openai",
"default_model": "gpt-4-turbo-preview",
// make sure ollama is running
"api_url": "http://localhost:11434/v1"
"default_model": {
"name": "gpt-4-turbo-preview:latest",
"max_tokens": 2048,
"keep_alive": -1
},
"name": "ollama"
}
},
"language_models": {
"ollama": {
"api_url": "http://localhost:11434"
}
},
// Inlay hints preconfigured by Zed: Go, Rust, Typescript and Svelte
Expand Down

0 comments on commit bb103e2

Please sign in to comment.