@fresh-editor/fresh-editor 0.1.63 → 0.1.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,160 @@
1
+ /// <reference path="./lib/fresh.d.ts" />
2
+
3
+ /**
4
+ * Python LSP Helper Plugin
5
+ *
6
+ * Provides user-friendly error handling for Python LSP server issues.
7
+ * When the Python LSP server fails to start, this plugin shows an
8
+ * actionable popup with installation instructions.
9
+ *
10
+ * Features:
11
+ * - Detects Python LSP server errors (pylsp, python-lsp-server)
12
+ * - Shows popup with install commands (pip, pipx)
13
+ * - Allows copying install commands to clipboard
14
+ * - Provides option to disable Python LSP
15
+ */
16
+
17
+ interface LspServerErrorData {
18
+ language: string;
19
+ server_command: string;
20
+ error_type: string;
21
+ message: string;
22
+ }
23
+
24
+ interface LspStatusClickedData {
25
+ language: string;
26
+ has_error: boolean;
27
+ }
28
+
29
+ interface ActionPopupResultData {
30
+ popup_id: string;
31
+ action_id: string;
32
+ }
33
+
34
+ // Install commands for Python LSP server (python-lsp-server / pylsp)
35
+ // pipx provides isolated installation (recommended)
36
+ // pip_all includes all optional dependencies (rope, pyflakes, etc.)
37
+ // See: https://github.com/python-lsp/python-lsp-server
38
+ const INSTALL_COMMANDS = {
39
+ pipx: "pipx install python-lsp-server",
40
+ pip: "pip install python-lsp-server",
41
+ pip_all: "pip install 'python-lsp-server[all]'",
42
+ };
43
+
44
+ // Track error state for Python LSP
45
+ let pythonLspError: { serverCommand: string; message: string } | null = null;
46
+
47
+ /**
48
+ * Handle LSP server errors for Python
49
+ */
50
+ globalThis.on_python_lsp_server_error = function (
51
+ data: LspServerErrorData
52
+ ): void {
53
+ // Only handle Python language errors
54
+ if (data.language !== "python") {
55
+ return;
56
+ }
57
+
58
+ editor.debug(
59
+ `python-lsp: Server error - ${data.error_type}: ${data.message}`
60
+ );
61
+
62
+ // Store error state for later reference
63
+ pythonLspError = {
64
+ serverCommand: data.server_command,
65
+ message: data.message,
66
+ };
67
+
68
+ // Show a status message for immediate feedback
69
+ if (data.error_type === "not_found") {
70
+ editor.setStatus(
71
+ `Python LSP server '${data.server_command}' not found. Click status bar for help.`
72
+ );
73
+ } else {
74
+ editor.setStatus(`Python LSP error: ${data.message}`);
75
+ }
76
+ };
77
+
78
+ // Register hook for LSP server errors
79
+ editor.on("lsp_server_error", "on_python_lsp_server_error");
80
+
81
+ /**
82
+ * Handle status bar click when there's a Python LSP error
83
+ */
84
+ globalThis.on_python_lsp_status_clicked = function (
85
+ data: LspStatusClickedData
86
+ ): void {
87
+ // Only handle Python language clicks when there's an error
88
+ if (data.language !== "python" || !pythonLspError) {
89
+ return;
90
+ }
91
+
92
+ editor.debug("python-lsp: Status clicked, showing help popup");
93
+
94
+ // Show action popup with install options
95
+ editor.showActionPopup({
96
+ id: "python-lsp-help",
97
+ title: "Python Language Server Not Found",
98
+ message: `"${pythonLspError.serverCommand}" provides code completion, diagnostics, and navigation for Python files. Copy a command below to install it, or search online for your platform.`,
99
+ actions: [
100
+ { id: "copy_pipx", label: `Copy: ${INSTALL_COMMANDS.pipx}` },
101
+ { id: "copy_pip", label: `Copy: ${INSTALL_COMMANDS.pip}` },
102
+ { id: "copy_pip_all", label: `Copy: ${INSTALL_COMMANDS.pip_all}` },
103
+ { id: "disable", label: "Disable Python LSP" },
104
+ { id: "dismiss", label: "Dismiss (ESC)" },
105
+ ],
106
+ });
107
+ };
108
+
109
+ // Register hook for status bar clicks
110
+ editor.on("lsp_status_clicked", "on_python_lsp_status_clicked");
111
+
112
+ /**
113
+ * Handle action popup results for Python LSP help
114
+ */
115
+ globalThis.on_python_lsp_action_result = function (
116
+ data: ActionPopupResultData
117
+ ): void {
118
+ // Only handle our popup
119
+ if (data.popup_id !== "python-lsp-help") {
120
+ return;
121
+ }
122
+
123
+ editor.debug(`python-lsp: Action selected - ${data.action_id}`);
124
+
125
+ switch (data.action_id) {
126
+ case "copy_pipx":
127
+ editor.setClipboard(INSTALL_COMMANDS.pipx);
128
+ editor.setStatus("Copied: " + INSTALL_COMMANDS.pipx);
129
+ break;
130
+
131
+ case "copy_pip":
132
+ editor.setClipboard(INSTALL_COMMANDS.pip);
133
+ editor.setStatus("Copied: " + INSTALL_COMMANDS.pip);
134
+ break;
135
+
136
+ case "copy_pip_all":
137
+ editor.setClipboard(INSTALL_COMMANDS.pip_all);
138
+ editor.setStatus("Copied: " + INSTALL_COMMANDS.pip_all);
139
+ break;
140
+
141
+ case "disable":
142
+ editor.disableLspForLanguage("python");
143
+ editor.setStatus("Python LSP disabled");
144
+ pythonLspError = null;
145
+ break;
146
+
147
+ case "dismiss":
148
+ case "dismissed":
149
+ // Just close the popup without action
150
+ break;
151
+
152
+ default:
153
+ editor.debug(`python-lsp: Unknown action: ${data.action_id}`);
154
+ }
155
+ };
156
+
157
+ // Register hook for action popup results
158
+ editor.on("action_popup_result", "on_python_lsp_action_result");
159
+
160
+ editor.debug("python-lsp: Plugin loaded");
@@ -0,0 +1,164 @@
1
+ /// <reference path="./lib/fresh.d.ts" />
2
+
3
+ /**
4
+ * Rust LSP Helper Plugin
5
+ *
6
+ * Provides user-friendly error handling for Rust LSP server issues.
7
+ * When rust-analyzer fails to start, this plugin shows an actionable
8
+ * popup with installation instructions.
9
+ *
10
+ * Features:
11
+ * - Detects Rust LSP server errors (rust-analyzer)
12
+ * - Shows popup with install commands (rustup, brew)
13
+ * - Allows copying install commands to clipboard
14
+ * - Provides option to disable Rust LSP
15
+ */
16
+
17
+ interface LspServerErrorData {
18
+ language: string;
19
+ server_command: string;
20
+ error_type: string;
21
+ message: string;
22
+ }
23
+
24
+ interface LspStatusClickedData {
25
+ language: string;
26
+ has_error: boolean;
27
+ }
28
+
29
+ interface ActionPopupResultData {
30
+ popup_id: string;
31
+ action_id: string;
32
+ }
33
+
34
+ // Install commands for Rust LSP server
35
+ // rustup is the official recommended method
36
+ // brew is a good alternative for macOS users
37
+ // See: https://rust-analyzer.github.io/book/installation.html
38
+ const INSTALL_COMMANDS = {
39
+ rustup: "rustup component add rust-analyzer",
40
+ brew: "brew install rust-analyzer",
41
+ };
42
+
43
+ // Track error state for Rust LSP
44
+ let rustLspError: { serverCommand: string; message: string } | null = null;
45
+
46
+ /**
47
+ * Handle LSP server errors for Rust
48
+ */
49
+ globalThis.on_rust_lsp_server_error = function (
50
+ data: LspServerErrorData
51
+ ): void {
52
+ // Only handle Rust language errors
53
+ if (data.language !== "rust") {
54
+ return;
55
+ }
56
+
57
+ editor.debug(`rust-lsp: Server error - ${data.error_type}: ${data.message}`);
58
+
59
+ // Store error state for later reference
60
+ rustLspError = {
61
+ serverCommand: data.server_command,
62
+ message: data.message,
63
+ };
64
+
65
+ // Show a status message for immediate feedback
66
+ if (data.error_type === "not_found") {
67
+ editor.setStatus(
68
+ `Rust LSP server '${data.server_command}' not found. Click status bar for help.`
69
+ );
70
+ } else {
71
+ editor.setStatus(`Rust LSP error: ${data.message}`);
72
+ }
73
+ };
74
+
75
+ // Register hook for LSP server errors
76
+ editor.on("lsp_server_error", "on_rust_lsp_server_error");
77
+
78
+ /**
79
+ * Handle status bar click when there's a Rust LSP error
80
+ */
81
+ globalThis.on_rust_lsp_status_clicked = function (
82
+ data: LspStatusClickedData
83
+ ): void {
84
+ editor.debug(
85
+ `rust-lsp: lsp_status_clicked hook received - language=${data.language}, has_error=${data.has_error}, rustLspError=${rustLspError ? "SET" : "NULL"}`
86
+ );
87
+
88
+ // Only handle Rust language clicks when there's an error
89
+ if (data.language !== "rust" || !rustLspError) {
90
+ editor.debug(
91
+ `rust-lsp: Skipping - language check=${data.language !== "rust"}, error check=${!rustLspError}`
92
+ );
93
+ return;
94
+ }
95
+
96
+ editor.debug("rust-lsp: Status clicked, showing help popup");
97
+
98
+ // Show action popup with install options
99
+ const result = editor.showActionPopup({
100
+ id: "rust-lsp-help",
101
+ title: "Rust Language Server Not Found",
102
+ message: `"${rustLspError.serverCommand}" provides code completion, diagnostics, and navigation for Rust files. Copy a command below to install it, or search online for your platform.`,
103
+ actions: [
104
+ { id: "copy_rustup", label: `Copy: ${INSTALL_COMMANDS.rustup}` },
105
+ { id: "copy_brew", label: `Copy: ${INSTALL_COMMANDS.brew}` },
106
+ { id: "disable", label: "Disable Rust LSP" },
107
+ { id: "dismiss", label: "Dismiss (ESC)" },
108
+ ],
109
+ });
110
+ editor.debug(`rust-lsp: showActionPopup returned ${result}`);
111
+ };
112
+
113
+ // Register hook for status bar clicks
114
+ editor.on("lsp_status_clicked", "on_rust_lsp_status_clicked");
115
+
116
+ /**
117
+ * Handle action popup results for Rust LSP help
118
+ */
119
+ globalThis.on_rust_lsp_action_result = function (
120
+ data: ActionPopupResultData
121
+ ): void {
122
+ editor.debug(
123
+ `rust-lsp: action_popup_result received - popup_id=${data.popup_id}, action_id=${data.action_id}`
124
+ );
125
+
126
+ // Only handle our popup
127
+ if (data.popup_id !== "rust-lsp-help") {
128
+ editor.debug("rust-lsp: Not our popup, skipping");
129
+ return;
130
+ }
131
+
132
+ editor.debug(`rust-lsp: Action selected - ${data.action_id}, rustLspError will remain SET`);
133
+
134
+ switch (data.action_id) {
135
+ case "copy_rustup":
136
+ editor.setClipboard(INSTALL_COMMANDS.rustup);
137
+ editor.setStatus("Copied: " + INSTALL_COMMANDS.rustup);
138
+ break;
139
+
140
+ case "copy_brew":
141
+ editor.setClipboard(INSTALL_COMMANDS.brew);
142
+ editor.setStatus("Copied: " + INSTALL_COMMANDS.brew);
143
+ break;
144
+
145
+ case "disable":
146
+ editor.disableLspForLanguage("rust");
147
+ editor.setStatus("Rust LSP disabled");
148
+ rustLspError = null;
149
+ break;
150
+
151
+ case "dismiss":
152
+ case "dismissed":
153
+ // Just close the popup without action
154
+ break;
155
+
156
+ default:
157
+ editor.debug(`rust-lsp: Unknown action: ${data.action_id}`);
158
+ }
159
+ };
160
+
161
+ // Register hook for action popup results
162
+ editor.on("action_popup_result", "on_rust_lsp_action_result");
163
+
164
+ editor.debug("rust-lsp: Plugin loaded");
@@ -0,0 +1,165 @@
1
+ /// <reference path="./lib/fresh.d.ts" />
2
+
3
+ /**
4
+ * TypeScript/JavaScript LSP Helper Plugin
5
+ *
6
+ * Provides user-friendly error handling for TypeScript/JavaScript LSP server issues.
7
+ * When typescript-language-server fails to start, this plugin shows an actionable
8
+ * popup with installation instructions.
9
+ *
10
+ * Features:
11
+ * - Detects TypeScript LSP server errors (typescript-language-server, tsserver)
12
+ * - Shows popup with install commands (npm, yarn, pnpm)
13
+ * - Allows copying install commands to clipboard
14
+ * - Provides option to disable TypeScript LSP
15
+ */
16
+
17
+ interface LspServerErrorData {
18
+ language: string;
19
+ server_command: string;
20
+ error_type: string;
21
+ message: string;
22
+ }
23
+
24
+ interface LspStatusClickedData {
25
+ language: string;
26
+ has_error: boolean;
27
+ }
28
+
29
+ interface ActionPopupResultData {
30
+ popup_id: string;
31
+ action_id: string;
32
+ }
33
+
34
+ // Install commands for TypeScript LSP server
35
+ // Both typescript-language-server AND typescript packages are required
36
+ // See: https://github.com/typescript-language-server/typescript-language-server
37
+ const INSTALL_COMMANDS = {
38
+ npm: "npm install -g typescript-language-server typescript",
39
+ yarn: "yarn global add typescript-language-server typescript",
40
+ pnpm: "pnpm add -g typescript-language-server typescript",
41
+ };
42
+
43
+ // Languages handled by this plugin
44
+ const HANDLED_LANGUAGES = ["typescript", "javascript", "typescriptreact", "javascriptreact"];
45
+
46
+ // Track error state for TypeScript LSP
47
+ let tsLspError: { serverCommand: string; message: string; language: string } | null = null;
48
+
49
+ /**
50
+ * Handle LSP server errors for TypeScript/JavaScript
51
+ */
52
+ globalThis.on_typescript_lsp_server_error = function (
53
+ data: LspServerErrorData
54
+ ): void {
55
+ // Only handle TypeScript/JavaScript language errors
56
+ if (!HANDLED_LANGUAGES.includes(data.language)) {
57
+ return;
58
+ }
59
+
60
+ editor.debug(
61
+ `typescript-lsp: Server error - ${data.error_type}: ${data.message}`
62
+ );
63
+
64
+ // Store error state for later reference
65
+ tsLspError = {
66
+ serverCommand: data.server_command,
67
+ message: data.message,
68
+ language: data.language,
69
+ };
70
+
71
+ // Show a status message for immediate feedback
72
+ if (data.error_type === "not_found") {
73
+ editor.setStatus(
74
+ `TypeScript LSP server '${data.server_command}' not found. Click status bar for help.`
75
+ );
76
+ } else {
77
+ editor.setStatus(`TypeScript LSP error: ${data.message}`);
78
+ }
79
+ };
80
+
81
+ // Register hook for LSP server errors
82
+ editor.on("lsp_server_error", "on_typescript_lsp_server_error");
83
+
84
+ /**
85
+ * Handle status bar click when there's a TypeScript LSP error
86
+ */
87
+ globalThis.on_typescript_lsp_status_clicked = function (
88
+ data: LspStatusClickedData
89
+ ): void {
90
+ // Only handle TypeScript/JavaScript language clicks when there's an error
91
+ if (!HANDLED_LANGUAGES.includes(data.language) || !tsLspError) {
92
+ return;
93
+ }
94
+
95
+ editor.debug("typescript-lsp: Status clicked, showing help popup");
96
+
97
+ // Show action popup with install options
98
+ editor.showActionPopup({
99
+ id: "typescript-lsp-help",
100
+ title: "TypeScript Language Server Not Found",
101
+ message: `"${tsLspError.serverCommand}" provides code completion, diagnostics, and navigation for TypeScript/JavaScript files. Copy a command below to install it, or search online for your platform.`,
102
+ actions: [
103
+ { id: "copy_npm", label: `Copy: ${INSTALL_COMMANDS.npm}` },
104
+ { id: "copy_yarn", label: `Copy: ${INSTALL_COMMANDS.yarn}` },
105
+ { id: "copy_pnpm", label: `Copy: ${INSTALL_COMMANDS.pnpm}` },
106
+ { id: "disable", label: "Disable TypeScript LSP" },
107
+ { id: "dismiss", label: "Dismiss (ESC)" },
108
+ ],
109
+ });
110
+ };
111
+
112
+ // Register hook for status bar clicks
113
+ editor.on("lsp_status_clicked", "on_typescript_lsp_status_clicked");
114
+
115
+ /**
116
+ * Handle action popup results for TypeScript LSP help
117
+ */
118
+ globalThis.on_typescript_lsp_action_result = function (
119
+ data: ActionPopupResultData
120
+ ): void {
121
+ // Only handle our popup
122
+ if (data.popup_id !== "typescript-lsp-help") {
123
+ return;
124
+ }
125
+
126
+ editor.debug(`typescript-lsp: Action selected - ${data.action_id}`);
127
+
128
+ switch (data.action_id) {
129
+ case "copy_npm":
130
+ editor.setClipboard(INSTALL_COMMANDS.npm);
131
+ editor.setStatus("Copied: " + INSTALL_COMMANDS.npm);
132
+ break;
133
+
134
+ case "copy_yarn":
135
+ editor.setClipboard(INSTALL_COMMANDS.yarn);
136
+ editor.setStatus("Copied: " + INSTALL_COMMANDS.yarn);
137
+ break;
138
+
139
+ case "copy_pnpm":
140
+ editor.setClipboard(INSTALL_COMMANDS.pnpm);
141
+ editor.setStatus("Copied: " + INSTALL_COMMANDS.pnpm);
142
+ break;
143
+
144
+ case "disable":
145
+ // Disable for all TypeScript/JavaScript variants
146
+ editor.disableLspForLanguage("typescript");
147
+ editor.disableLspForLanguage("javascript");
148
+ editor.setStatus("TypeScript/JavaScript LSP disabled");
149
+ tsLspError = null;
150
+ break;
151
+
152
+ case "dismiss":
153
+ case "dismissed":
154
+ // Just close the popup without action
155
+ break;
156
+
157
+ default:
158
+ editor.debug(`typescript-lsp: Unknown action: ${data.action_id}`);
159
+ }
160
+ };
161
+
162
+ // Register hook for action popup results
163
+ editor.on("action_popup_result", "on_typescript_lsp_action_result");
164
+
165
+ editor.debug("typescript-lsp: Plugin loaded");