-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32a9f62
commit a57732f
Showing
3 changed files
with
49 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { minimatch } from 'minimatch'; | ||
import { MarkdownView } from 'obsidian'; | ||
import Markpilot from 'src/main'; | ||
import { APIClient, ChatMessage } from '..'; | ||
|
||
export class IgnoredFilter implements APIClient { | ||
constructor( | ||
private client: APIClient, | ||
private plugin: Markpilot, | ||
) {} | ||
|
||
fetchChat(messages: ChatMessage[]) { | ||
// No filter for chats. | ||
return this.client.fetchChat(messages); | ||
} | ||
|
||
async fetchCompletions(prefix: string, suffix: string) { | ||
const { plugin } = this; | ||
const { settings } = plugin; | ||
|
||
const view = plugin.app.workspace.getActiveViewOfType(MarkdownView); | ||
const file = view?.file; | ||
const content = view?.editor.getValue(); | ||
const isIgnoredFile = settings.completions.ignoredFiles.some( | ||
(pattern) => file?.path && minimatch(file?.path, pattern), | ||
); | ||
const hasIgnoredTags = settings.completions.ignoredTags.some( | ||
(tag) => content && new RegExp(tag, 'gm').test(content), | ||
); | ||
if (isIgnoredFile || hasIgnoredTags) { | ||
return; | ||
} | ||
|
||
return this.client.fetchCompletions(prefix, suffix); | ||
} | ||
|
||
testConnection() { | ||
return this.client.testConnection(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters