Skip to content

Commit

Permalink
cleanup PR
Browse files Browse the repository at this point in the history
  • Loading branch information
mProjectsCode committed Jan 11, 2025
1 parent 97a491e commit 457dd60
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/checkPR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Run Checks and Tests on PR

on: pull_request

jobs:
check:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install Dependencies
id: build
run: |
bun install
- name: Run Checks
run: |
bun run check
8 changes: 2 additions & 6 deletions src/Highlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type ShikiPlugin from 'src/main';
import {
bundledLanguages,
createHighlighter,
type DynamicImportLanguageRegistration,
type LanguageRegistration,
type Highlighter,
type TokensResult,
Expand Down Expand Up @@ -55,10 +54,7 @@ export class CodeHighlighter {
await this.loadEC();
await this.loadShiki();

this.supportedLanguages = [
...Object.keys(bundledLanguages),
...this.customLanguages.map(i => i.name)
];
this.supportedLanguages = [...Object.keys(bundledLanguages), ...this.customLanguages.map(i => i.name)];
}

async unload(): Promise<void> {
Expand Down Expand Up @@ -215,7 +211,7 @@ export class CodeHighlighter {
if (!this.obsidianSafeLanguageNames().includes(lang)) {
return undefined;
}
// load bundled language ​​when needed
// load bundled language when needed
if (!this.shiki.getLoadedLanguages().includes(lang)) {
await this.shiki.loadLanguage(lang as BundledLanguage);
}
Expand Down
18 changes: 9 additions & 9 deletions src/codemirror/Cm6_ViewPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export function createCm6Plugin(plugin: ShikiPlugin) {
constructor(view: EditorView) {
this.view = view;
this.decorations = Decoration.none;
this.updateWidgets(view);
void this.updateWidgets(view);

plugin.updateCm6Plugin = (): void => {
this.forceUpdate();
plugin.updateCm6Plugin = (): Promise<void> => {
return this.forceUpdate();
};
}

Expand All @@ -46,12 +46,12 @@ export function createCm6Plugin(plugin: ShikiPlugin) {
// we handle doc changes and selection changes here
if (update.docChanged || update.selectionSet) {
this.view = update.view;
this.updateWidgets(update.view, update.docChanged);
void this.updateWidgets(update.view, update.docChanged);
}
}

forceUpdate(): void {
this.updateWidgets(this.view);
async forceUpdate(): Promise<void> {
await this.updateWidgets(this.view);

this.view.dispatch(this.view.state.update({}));
}
Expand All @@ -70,7 +70,7 @@ export function createCm6Plugin(plugin: ShikiPlugin) {
async updateWidgets(view: EditorView, docChanged: boolean = true): Promise<void> {
let lang = '';
let state: SyntaxNode[] = [];
let decoQueue: DecoQueueNode[] = [];
const decoQueue: DecoQueueNode[] = [];

// const t1 = performance.now();

Expand Down Expand Up @@ -98,7 +98,7 @@ export function createCm6Plugin(plugin: ShikiPlugin) {
lang: match[1],
content: match[2],
hideLang: this.isLivePreview(view.state) && !hasSelectionOverlap,
hideTo: node.from + match[1].length + 3 // hide `{lang} `
hideTo: node.from + match[1].length + 3, // hide `{lang} `
});
}
} else {
Expand Down Expand Up @@ -135,7 +135,7 @@ export function createCm6Plugin(plugin: ShikiPlugin) {
from: start,
to: end,
lang,
content: Cm6_Util.getContent(view.state, start, end)
content: Cm6_Util.getContent(view.state, start, end),
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class ShikiPlugin extends Plugin {
activeCodeBlocks!: Map<string, CodeBlock[]>;
settings!: Settings;
loadedSettings!: Settings;
updateCm6Plugin!: () => void;
updateCm6Plugin!: () => Promise<void>;

codeBlockProcessors: MarkdownPostProcessor[] = [];

Expand Down Expand Up @@ -65,7 +65,7 @@ export default class ShikiPlugin extends Plugin {
}
}

this.updateCm6Plugin();
await this.updateCm6Plugin();
}

async registerPrismPlugin(): Promise<void> {
Expand Down

0 comments on commit 457dd60

Please sign in to comment.