diff --git a/config/code_actions/gitcommit/enhance.lua b/config/code_actions/gitcommit/enhance.lua new file mode 100644 index 0000000..56550f4 --- /dev/null +++ b/config/code_actions/gitcommit/enhance.lua @@ -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: + + +]], git_draft_message, [[ +Assistant: ]] }) + end, + + placement_range = function(selection_range) + return active_doc:root():range() + end +} + +return M diff --git a/src/main.rs b/src/main.rs index a14bea8..e1345c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 {