Skip to content

Commit

Permalink
Add Git Commit Code Action with Commit Message Guidelines
Browse files Browse the repository at this point in the history
This commit adds a new code action for creating Git commit messages that follow
best practices. The code action provides a template with clear guidelines for
the commit message structure, including the subject line and body.
  • Loading branch information
PatWie committed Aug 7, 2024
1 parent ed2230d commit 0106e91
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions config/code_actions/gitcommit/enhance.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

local prompt = [[
Please take the following unstructured draft text, which may contain typos and unclear phrasing,
and transform it into a clear, concise, and well-structured Git commit message according
to the following rules:
1. Separate subject from body with a blank line
2. Limit the subject line to 50 characters
3. Capitalize the subject line
4. Do not end the subject line with a period
5. Use the imperative mood in the subject line
6. Wrap the body at 72 characters
7. Use the body to explain what and why vs. how
---
]]

local M = {
is_triggered = function(selection_range)
return true
end,

action_name = function()
return "Improve Git Message"
end,

process_answer = function(text, selection_range)
return text
end,

create_prompt = function(selection_range)
local git_draft_message = active_doc:text_from_range(active_doc:root():range())
return table.concat({
[[ Human:
]], prompt, [[
Here is the unstructured draft text:
<task>
]], git_draft_message, [[</task>
Assistant: ]] })
end,

placement_range = function(selection_range)
return active_doc:root():range()
end
}

return M
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tower_lsp::jsonrpc::Result;
use tower_lsp::lsp_types::*;
use tower_lsp::{Client, LanguageServer, LspService, Server};

const SUPPORTED_LANGUAGES: [&str; 6] = ["rust", "python", "text", "go", "__all__", "markdown"];
const SUPPORTED_LANGUAGES: [&str; 7] = ["rust", "python", "text", "go", "__all__", "markdown", "gitcommit"];

#[derive(Debug, Serialize, Deserialize)]
pub struct ResolveActionKind {
Expand Down

0 comments on commit 0106e91

Please sign in to comment.