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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { useTitle } from '@vueuse/core'
import { storeToRefs } from 'pinia'
import { computed } from 'vue'
import { IDE_TITLES_TO_KEYS_MAP } from '@/shared/constants'
import { pathToIDEFilePath } from '@/shared/lib/helpers/pathToIDEFilePath'
import { THEME_MODES, useSettingsStore } from '@/shared/stores'
import { BadgeNumber, IconSvg } from '@/shared/ui'

Expand Down Expand Up @@ -115,24 +117,29 @@ useTitle('Settings | Buggregator')
</div>

<div class="settings-page-content__title">
Code Editor Open Link:
Favorite Code Editor:
</div>

<div class="settings-page-content__control">
<div>
<label class="settings-page-content__control-label">
<input
class="settings-page-content__control-input"
type="text"
<select
class="settings-page-content__control-select"
:value="codeEditor"
@change="changeCodeEditor"
>
&nbsp;://open?file=/App/Modules/Logger.php&line=12
<option
v-for="(title, key) in IDE_TITLES_TO_KEYS_MAP"
:key="key"
:value="key"
>
{{ title }}
</option>
</select>
</label>

<div class="settings-page-content__control-description">
Example of link to open files in code editor. You can replace the name editor with a more
preferable one
Sample editor link: {{ pathToIDEFilePath(codeEditor, '/App/Modules/Logger.php', 12) }}
</div>
</div>
</div>
Expand Down Expand Up @@ -180,14 +187,14 @@ useTitle('Settings | Buggregator')
}

.settings-page-content__control-label {
@apply text-xl font-bold items-center flex;
@apply text-xl font-bold flex;
}

.settings-page-content__control-input {
@apply border-gray-600 p-1 rounded w-[140px] bg-gray-200 dark:bg-gray-600;
.settings-page-content__control-select {
@apply border-gray-600 p-1 rounded min-w-[140px] bg-gray-200 dark:bg-gray-600 text-sm;
}

.settings-page-content__control-description {
@apply text-xs mt-2;
@apply text-xs mt-2 flex flex-shrink-0;
}
</style>
1 change: 1 addition & 0 deletions src/shared/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './pages'
export * from './settings'
39 changes: 39 additions & 0 deletions src/shared/constants/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export enum IDE_KEYS {
VSCODE = "vscode",
CURSOR = "cursor",
PHPSTORM = "phpstorm",
IDEA = "idea",
WEBSTORM = "webstorm",
PYCHARM = "pycharm",
RIDER = "rider",
GOLAND = "goland",
CLION = "clion",
RUBYMINE = "rubymine",
DATAGRIP = "datagrip",
FLEET = "fleet",
SUBLIME_TEXT = "subl",
ATOM = "atom",
TEXTMATE = "txmt",
NOVA = "nova",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need t add vim and emacs to supported code editors

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need to add code editor "ZED"

}

export const IDE_KEY_DEFAULT = IDE_KEYS.VSCODE;

export const IDE_TITLES_TO_KEYS_MAP: Record<string, string> = {
[IDE_KEYS.VSCODE]: "VS Code",
[IDE_KEYS.CURSOR]: "Cursor",
[IDE_KEYS.PHPSTORM]: "JetBrains PhpStorm",
[IDE_KEYS.IDEA]: "JetBrains IntelliJ IDEA",
[IDE_KEYS.WEBSTORM]: "JetBrains WebStorm",
[IDE_KEYS.PYCHARM]: "JetBrains PyCharm",
[IDE_KEYS.RIDER]: "JetBrains Rider",
[IDE_KEYS.GOLAND]: "JetBrains GoLand",
[IDE_KEYS.CLION]: "JetBrains CLion",
[IDE_KEYS.RUBYMINE]: "JetBrains RubyMine",
[IDE_KEYS.DATAGRIP]: "JetBrains DataGrip",
[IDE_KEYS.FLEET]: "JetBrains Fleet",
[IDE_KEYS.SUBLIME_TEXT]: "Sublime Text",
[IDE_KEYS.ATOM]: "Atom",
[IDE_KEYS.TEXTMATE]: "TextMate",
[IDE_KEYS.NOVA]: "Nova",
}
58 changes: 58 additions & 0 deletions src/shared/lib/helpers/pathToIDEFilePath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {IDE_KEYS, IDE_TITLES_TO_KEYS_MAP} from "../../constants";


function toFileUrl(posixAbsPath: string): string {
// Input example is POSIX (/app/...), so keep it simple.
return `file://${posixAbsPath.startsWith("/") ? "" : "/"}${posixAbsPath}`;
}

/**
* Build a deep link for the given IDE for a POSIX absolute path + optional line.
* Returns null for IDEs without a reliable scheme (e.g., Xcode).
*/
export function pathToIDEFilePath(ide: IDE_KEYS, source: string, line?: number): string | null {
if (!source) throw new Error("source is required");

const ln = typeof line === "number" && Number.isFinite(line) && line > 0 ? line : null;

if (ide === IDE_KEYS.VSCODE) {
return `${IDE_KEYS.VSCODE}://file${source}${ln ? `:${ln}:1` : ""}`;
}

if (ide === IDE_KEYS.CURSOR) {
return `${IDE_KEYS.CURSOR}://file${source}${ln ? `:${ln}` : ""}`;
}

if (IDE_TITLES_TO_KEYS_MAP[ide].startsWith("JetBrains ")) {
const params = new URLSearchParams({ source });
if (ln) params.set("line", String(ln));
return `jetbrains://${ide}/navigate/reference?${params.toString()}`;
}

if (ide === IDE_KEYS.SUBLIME_TEXT) {
const params = new URLSearchParams({ url: toFileUrl(source) });
if (ln) params.set("line", String(ln));
return `${IDE_KEYS.SUBLIME_TEXT}://open?${params.toString()}`;
}

if (ide === IDE_KEYS.ATOM) {
const params = new URLSearchParams({ filename: source });
if (ln) params.set("line", String(ln));
return `${IDE_KEYS.ATOM}://core/open/file?${params.toString()}`;
}


if (ide === IDE_KEYS.TEXTMATE) {
const params = new URLSearchParams({ url: toFileUrl(source) });
if (ln) params.set("line", String(ln));
return `${IDE_KEYS.TEXTMATE}://open?${params.toString()}`;
}

if (ide === IDE_KEYS.NOVA) {
const params = new URLSearchParams({ path: source });
if (ln) params.set("line", String(ln));
return `${IDE_KEYS.NOVA}://core/open/file?${params.toString()}`;
}

return null;
}
5 changes: 3 additions & 2 deletions src/shared/stores/settings/local-storage-actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {IDE_KEYS, IDE_KEY_DEFAULT} from "../../constants";
import {LocalStorageKeys} from "../../types";
import {THEME_MODES} from "./constants";

Expand Down Expand Up @@ -71,10 +72,10 @@ export const setStoredEventsCountVisibility = (state: boolean) => {
}


export const getStoredPrimaryCodeEditor = (): string => {
export const getStoredPrimaryCodeEditor = (): IDE_KEYS => {
const storedCodeEditor = window?.localStorage?.getItem(LocalStorageKeys.CodeEditor);

return storedCodeEditor || '';
return storedCodeEditor && Object.values(IDE_KEYS).includes(storedCodeEditor as IDE_KEYS) ? storedCodeEditor as IDE_KEYS : IDE_KEY_DEFAULT;
};

export const setStoredPrimaryCodeEditor = (editor: string) => {
Expand Down
3 changes: 2 additions & 1 deletion src/shared/stores/settings/settings-store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {defineStore} from "pinia";
import {IDE_KEY_DEFAULT} from "../../constants";
import {REST_API_URL} from "../../lib/io/constants";
import {type EventType, EventTypes, type TSettings} from "../../types";
import {THEME_MODES} from "./constants";
Expand All @@ -19,7 +20,7 @@ export const useSettingsStore = defineStore("settingsStore", {
isFetched: false,
isAuthEnabled: false,
authLogicUrl: '/login',
codeEditor: getStoredPrimaryCodeEditor() || 'phpstorm',
codeEditor: getStoredPrimaryCodeEditor() || IDE_KEY_DEFAULT,
themeType: getStoredActiveTheme(),
isFixedHeader: getStoredFixedHeader(),
isVisibleEventCounts: getStoredEventsCountVisibility(),
Expand Down
Loading