Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
### Added
- Add `Summarize and New Context` command
- Resolve `@import` directives in user selection text
- Add configurable quote character for indentation (`markdown.copilot.indentation.quoteCharacter`)

### Changed
- Make `@import` directives only activate at the beginning of a line
Expand Down Expand Up @@ -300,4 +301,4 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
[0.0.4]: https://github.com/kurusugawa-computer/markdown-copilot-vscode/compare/v0.0.3...v0.0.4
[0.0.3]: https://github.com/kurusugawa-computer/markdown-copilot-vscode/compare/v0.0.2...v0.0.3
[0.0.2]: https://github.com/kurusugawa-computer/markdown-copilot-vscode/compare/v0.0.1...v0.0.2
[0.0.1]: https://github.com/kurusugawa-computer/markdown-copilot-vscode/releases/tag/v0.0.1
[0.0.1]: https://github.com/kurusugawa-computer/markdown-copilot-vscode/releases/tag/v0.0.1
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@
"minimum": 0,
"maximum": 1,
"markdownDescription": "%config.options.temperature.description%"
},
"markdown.copilot.indentation.quoteCharacter": {
"type": "string",
"default": ">",
"markdownDescription": "%config.indentation.quoteCharacter.description%"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion package.nls.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
"config.backend.protocol.description": "バックエンドプロトコルを指定できます。`OpenAI`、`Azure`、`Ollama`、`OpenRouter`がサポートされています。",
"config.options.model.description": "[Models](https://platform.openai.com/docs/models)にリストされているモデルを指定できます。`→ Model Name Text`を選択した場合、次の設定が使用されます。",
"config.options.modelNameText.description": "バックエンドによって異なるモデル名をテキストとして指定できます。",
"config.options.temperature.description": "`0.0`から`1.0`までの値、または空を指定できます。空の場合、この設定は省略されます。`0.8`のような高い値を設定すると出力はよりランダムになり、`0.2`のような低い値を設定すると出力はより集中して決定的になります。[FAQ](https://platform.openai.com/docs/guides/text-generation/how-should-i-set-the-temperature-parameter)が値の決定に役立ちます。"
"config.options.temperature.description": "`0.0`から`1.0`までの値、または空を指定できます。空の場合、この設定は省略されます。`0.8`のような高い値を設定すると出力はよりランダムになり、`0.2`のような低い値を設定すると出力はより集中して決定的になります。[FAQ](https://platform.openai.com/docs/guides/text-generation/how-should-i-set-the-temperature-parameter)が値の決定に役立ちます。",
"config.indentation.quoteCharacter.description": "Markdownの引用インデントに使用する文字を指定できます。デフォルトは `>` ですが、`>|` などの他の文字も使用できます。"
}
5 changes: 3 additions & 2 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
"config.backend.protocol.description": "Can specify the backend protocol. `OpenAI`, `Azure`, `Ollama`, `OpenRouter` are supported.",
"config.options.model.description": "Can specify the models listed in [Models](https://platform.openai.com/docs/models), if `→ Model Name Text` selected, the following setting will be used.",
"config.options.modelNameText.description": "Can specify the model name as text, which varies by backend.",
"config.options.temperature.description": "Can specify a value between `0.0` and `1.0` or empty. If empty, the temperature setting is omitted. Higher values like `0.8` will make the output more random, while lower values like `0.2` will make it more focused and deterministic. [FAQ](https://platform.openai.com/docs/guides/text-generation/how-should-i-set-the-temperature-parameter) helps to determine the value."
}
"config.options.temperature.description": "Can specify a value between `0.0` and `1.0` or empty. If empty, the temperature setting is omitted. Higher values like `0.8` will make the output more random, while lower values like `0.2` will make it more focused and deterministic. [FAQ](https://platform.openai.com/docs/guides/text-generation/how-should-i-set-the-temperature-parameter) helps to determine the value.",
"config.indentation.quoteCharacter.description": "Can specify the character(s) used for quote indentation in Markdown. Default is `>`, but you can use characters like `>|` or other combinations."
}
3 changes: 2 additions & 1 deletion package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
"config.backend.protocol.description": "可以指定后端协议。支持 `OpenAI`, `Azure`, `Ollama`, `OpenRouter`。",
"config.options.model.description": "可指定[Models](https://platform.openai.com/docs/models)中列出的模型, 如果选择 `→ Model Name Text`, 将使用下一个配置。",
"config.options.modelNameText.description": "可以文本形式指定模型名称, 不同后端可能有不同的命名规则。",
"config.options.temperature.description": "可指定一个介于`0.0`和`1.0`之间的值或留空。如果留空, 则会省略该设置。`0.8`这样的较高值会使输出更加随机, 而`0.2`这样的较低值会使输出更加集中和确定。[FAQ](https://platform.openai.com/docs/guides/text-generation/how-should-i-set-the-temperature-parameter) 可帮助确定该值。"
"config.options.temperature.description": "可指定一个介于`0.0`和`1.0`之间的值或留空。如果留空, 则会省略该设置。`0.8`这样的较高值会使输出更加随机, 而`0.2`这样的较低值会使输出更加集中和确定。[FAQ](https://platform.openai.com/docs/guides/text-generation/how-should-i-set-the-temperature-parameter) 可帮助确定该值。",
"config.indentation.quoteCharacter.description": "可以指定用于 Markdown 引用缩进的字符。默认为 `>`,但您可以使用 `>|` 等其他字符组合。"
}
10 changes: 6 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { adjustStartToLineHead, toOverflowAdjustedRange } from './utils';
import * as config from './utils/configuration';
import { ContextDecorator, ContextOutline } from './utils/context';
import { EditCursor } from './utils/editCursor';
import { indentQuote, outdentQuote } from './utils/indention';
import * as indention from './utils/indention';
import * as l10n from './utils/localization';
import * as logging from './utils/logging';

Expand Down Expand Up @@ -73,7 +73,7 @@ export function activate(context: vscode.ExtensionContext) {
textEditor.edit(editBuilder =>
editBuilder.replace(
range,
indentQuote(textEditor.document.getText(range), 1)
indention.indentQuote(textEditor.document.getText(range), 1)
)
);
}));
Expand All @@ -86,7 +86,7 @@ export function activate(context: vscode.ExtensionContext) {
textEditor.edit(editBuilder =>
editBuilder.replace(
range,
outdentQuote(textEditor.document.getText(range), 1)
indention.outdentQuote(textEditor.document.getText(range), 1)
)
);
}));
Expand Down Expand Up @@ -118,6 +118,8 @@ export function activate(context: vscode.ExtensionContext) {
catch { /* Ignore errors */ }
try { contextDecorator.onDidChangeConfiguration(event); }
catch { /* Ignore errors */ }
try { indention.onDidChangeConfiguration(event); }
catch { /* Ignore errors */ }
}
));

Expand Down Expand Up @@ -192,4 +194,4 @@ export function activate(context: vscode.ExtensionContext) {

export function deactivate() {
EditCursor.onDeactivate();
}
}
5 changes: 5 additions & 0 deletions src/utils/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,9 @@ export class Configuration {
get optionsTemperature(): number {
return this.workspaceConfiguration.get<number>("markdown.copilot.options.temperature")!;
}

get indentationQuoteCharacter(): string {
const char = this.workspaceConfiguration.get<string>("markdown.copilot.indentation.quoteCharacter");
return char !== undefined && char.trim().length > 0 ? char : ">";
}
}
72 changes: 64 additions & 8 deletions src/utils/indention.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,87 @@
/*
* Utilities for handling quote indentation in markdown text.
*/
import * as vscode from 'vscode';
import * as config from "./configuration";

let quoteIndentationPatternCache: RegExp | null = null;
let quoteHeadPatternCache: RegExp | null = null;
let currentQuoteChar: string = '';

/**
* Initialize or update the RegExp cache based on the current configuration
*/
export function updateRegExpCache(): void {
const quoteChar = config.get().indentationQuoteCharacter;

if (currentQuoteChar === quoteChar) { return; }
currentQuoteChar = quoteChar;
quoteIndentationPatternCache = new RegExp(`^(${quoteChar}[ \t]?)+`);
quoteHeadPatternCache = new RegExp(`^(${quoteChar}[ \t]?)`);
}

/**
* Handle configuration changes for indentation settings
*/
export function onDidChangeConfiguration(event: vscode.ConfigurationChangeEvent): void {
if (!event.affectsConfiguration('markdown.copilot.indentation.quoteCharacter')) { return; }
updateRegExpCache();
}

/**
* Get the cached quote indentation pattern
*/
function getQuoteIndentationPattern(): RegExp {
if (!quoteIndentationPatternCache) {
updateRegExpCache();
}
return quoteIndentationPatternCache!;
}

/**
* Get the cached quote head pattern
*/
function getQuoteHeadPattern(): RegExp {
if (!quoteHeadPatternCache) {
updateRegExpCache();
}
return quoteHeadPatternCache!;
}

export function outdentQuote(text: string, level: number): string {
return text.replace(new RegExp(`^(>[ \t]?){0,${level}}`, "gm"), "");
const quoteChar = currentQuoteChar || config.get().indentationQuoteCharacter;
return text.replace(new RegExp(`^(${quoteChar}[ \t]?){0,${level}}`, "gm"), "");
}

export function indentQuote(text: string, level: number): string {
const headQuoteMatch = text.match(/^(>[ \t]?)/);
const quoteChar = currentQuoteChar || config.get().indentationQuoteCharacter;
const headQuoteMatch = text.match(getQuoteHeadPattern());
const quoteIndentText = headQuoteMatch === null
? "> "
? quoteChar + " "
: headQuoteMatch[1];
return text.replace(/(?<!\r)^/gm, quoteIndentText.repeat(level));
}

const quoteIndentationPattern = /^(>[ \t]?)+/;
export function getQuoteIndent(lineText: string): string {
const match = lineText.match(quoteIndentationPattern);
const match = lineText.match(getQuoteIndentationPattern());
if (match === null) { return ""; }
return match[0];
}

export function countQuoteIndent(lineText: string): number {
const quoteHead = getQuoteIndent(lineText);
const quoteChar = currentQuoteChar || config.get().indentationQuoteCharacter;
let count = 0;
for (const c of quoteHead) {
count += +(c === '>');
let i = 0;

while (i < quoteHead.length) {
if (quoteHead.substring(i, i + quoteChar.length) === quoteChar) {
count++;
i += quoteChar.length;
} else {
i++;
}
}

return count;
}
}
Loading