10 10
11每個外掛程式都透過語言伺服器協定 (LSP) 將 Claude Code 連接到一種語言的語言伺服器。您從 Anthropic 的官方市集安裝外掛程式,並在您的機器上安裝語言伺服器二進位檔。11每個外掛程式都透過語言伺服器協定 (LSP) 將 Claude Code 連接到一種語言的語言伺服器。您從 Anthropic 的官方市集安裝外掛程式,並在您的機器上安裝語言伺服器二進位檔。
12 12
13<Note>13> [!NOTE]
14 Code intelligence 外掛程式在終端機工作階段中運作。在[雲端工作階段](/docs/zh-TW/claude-code-on-the-web)中,Claude Code 不會啟動外掛程式語言伺服器,因此 Claude 在那裡無法取得診斷或程式碼導覽。若要撰寫您自己的語言伺服器外掛程式,或連接沒有外掛程式的語言伺服器,請參閱[外掛程式元件中的 LSP 伺服器](/docs/zh-TW/plugins/components#lsp-servers)。14>
15</Note>15> Code intelligence 外掛程式在終端機工作階段中運作。在[雲端工作階段](/docs/zh-TW/claude-code-on-the-web)中,Claude Code 不會啟動外掛程式語言伺服器,因此 Claude 在那裡無法取得診斷或程式碼導覽。若要撰寫您自己的語言伺服器外掛程式,或連接沒有外掛程式的語言伺服器,請參閱[外掛程式元件中的 LSP 伺服器](/docs/zh-TW/plugins/components#lsp-servers)。
16 16
17若要開始使用,請在[安裝 code intelligence 外掛程式](#install-a-code-intelligence-plugin)下的表格中找到您的語言。該表格中的外掛程式來自 Anthropic 的[官方外掛程式市集](/docs/zh-TW/plugins/anthropic-marketplaces)。17若要開始使用,請在[安裝 code intelligence 外掛程式](#install-a-code-intelligence-plugin)下的表格中找到您的語言。該表格中的外掛程式來自 Anthropic 的[官方外掛程式市集](/docs/zh-TW/plugins/anthropic-marketplaces)。
18 18
19如果您已經看到 **LSP 外掛程式建議**對話框,請參閱[接受或關閉建議對話框](#accept-or-dismiss-the-recommendation-dialog)以了解每個選擇的作用。19如果您已經看到 **LSP 外掛程式建議**對話框,請參閱[接受或關閉建議對話框](#accept-or-dismiss-the-recommendation-dialog)以了解每個選擇的作用。
20 20
21<h2 id="install-a-code-intelligence-plugin">21## 安裝 code intelligence 外掛程式
22 安裝 code intelligence 外掛程式
23</h2>
24 22
25Code intelligence 外掛程式告訴 Claude Code 哪個命令啟動語言伺服器以及它處理哪些檔案副檔名。它不包含語言伺服器。先安裝語言伺服器二進位檔,然後安裝外掛程式,最後確認伺服器啟動。23Code intelligence 外掛程式告訴 Claude Code 哪個命令啟動語言伺服器以及它處理哪些檔案副檔名。它不包含語言伺服器。先安裝語言伺服器二進位檔,然後安裝外掛程式,最後確認伺服器啟動。
26 24
27<Steps>25**1. 安裝語言伺服器二進位檔**
28 <Step title="安裝語言伺服器二進位檔">
29 在下表中找到您的語言,並安裝其列中的二進位檔。如果您的語言未列出,請參閱[新增沒有官方外掛程式的語言](#add-a-language-without-an-official-plugin)。
30 26
31 | 語言 | 外掛程式 | 二進位檔 |27在下表中找到您的語言,並安裝其列中的二進位檔。如果您的語言未列出,請參閱[新增沒有官方外掛程式的語言](#add-a-language-without-an-official-plugin)。
32 | :- | :- | :- |
33 | C/C++ | [`clangd-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/clangd-lsp) | `clangd` |
34 | C# | [`csharp-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/csharp-lsp) | `csharp-ls` |
35 | Go | [`gopls-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/gopls-lsp) | `gopls` |
36 | Java | [`jdtls-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/jdtls-lsp) | `jdtls` |
37 | Kotlin | [`kotlin-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/kotlin-lsp) | `kotlin-lsp` |
38 | Liquid | [`liquid-lsp`](https://github.com/Shopify/liquid-skills/tree/main/plugins/liquid-lsp) | `shopify`,來自 Shopify CLI |
39 | Lua | [`lua-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/lua-lsp) | `lua-language-server` |
40 | PHP | [`php-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/php-lsp) | `intelephense` |
41 | Python | [`pyright-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/pyright-lsp) | `pyright-langserver` |
42 | Ruby | [`ruby-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/ruby-lsp) | `ruby-lsp` |
43 | Rust | [`rust-analyzer-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/rust-analyzer-lsp) | `rust-analyzer` |
44 | Swift | [`swift-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/swift-lsp) | `sourcekit-lsp` |
45 | TypeScript 和 JavaScript | [`typescript-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/typescript-lsp) | `typescript-language-server` |
46 28
47 Anthropic 維護表格中的每個外掛程式,除了 `liquid-lsp` 外,該外掛程式由 Shopify 維護,官方市集也列出了它。29| 語言 | 外掛程式 | 二進位檔 |
30| :- | :- | :- |
31| C/C++ | [`clangd-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/clangd-lsp) | `clangd` |
32| C# | [`csharp-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/csharp-lsp) | `csharp-ls` |
33| Go | [`gopls-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/gopls-lsp) | `gopls` |
34| Java | [`jdtls-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/jdtls-lsp) | `jdtls` |
35| Kotlin | [`kotlin-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/kotlin-lsp) | `kotlin-lsp` |
36| Liquid | [`liquid-lsp`](https://github.com/Shopify/liquid-skills/tree/main/plugins/liquid-lsp) | `shopify`,來自 Shopify CLI |
37| Lua | [`lua-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/lua-lsp) | `lua-language-server` |
38| PHP | [`php-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/php-lsp) | `intelephense` |
39| Python | [`pyright-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/pyright-lsp) | `pyright-langserver` |
40| Ruby | [`ruby-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/ruby-lsp) | `ruby-lsp` |
41| Rust | [`rust-analyzer-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/rust-analyzer-lsp) | `rust-analyzer` |
42| Swift | [`swift-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/swift-lsp) | `sourcekit-lsp` |
43| TypeScript 和 JavaScript | [`typescript-lsp`](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/typescript-lsp) | `typescript-language-server` |
48 44
49 若要找到安裝二進位檔的命令,請按照表格中的外掛程式連結前往其 README。對於 TypeScript,該命令是 `npm install -g typescript-language-server typescript`。45Anthropic 維護表格中的每個外掛程式,除了 `liquid-lsp` 外,該外掛程式由 Shopify 維護,官方市集也列出了它。
50 46
51 安裝二進位檔後,確認它在您啟動 `claude` 的 shell 的 `PATH` 上,例如使用 `which typescript-language-server`,或在 PowerShell 中使用 `Get-Command typescript-language-server`。47若要找到安裝二進位檔的命令,請按照表格中的外掛程式連結前往其 README。對於 TypeScript,該命令是 `npm install -g typescript-language-server typescript`。
52 </Step>
53 48
54 <Step title="安裝外掛程式">49安裝二進位檔後,確認它在您啟動 `claude` 的 shell 的 `PATH` 上,例如使用 `which typescript-language-server`,或在 PowerShell 中使用 `Get-Command typescript-language-server`。
55 在 VS Code 擴充功能或桌面應用程式中,請改為按照[安裝外掛程式](/docs/zh-TW/plugins/install#install-a-plugin)操作,而非執行此步驟。在終端機中,執行 `claude` 啟動 Claude Code,然後在其提示字元中輸入以下內容,將 `typescript-lsp` 替換為步驟 1 表格中為您的語言列出的外掛程式:
56 50
57 ```51**2. 安裝外掛程式**
58 /plugin install typescript-lsp@claude-plugins-official
59 ```
60 52
61 確認訊息會說明外掛程式現在是否處於作用中或需要 `/reload-plugins`。如果安裝失敗並顯示 `Marketplace "claude-plugins-official" not found`,請參閱[該錯誤的疑難排解項目](/docs/zh-TW/plugins/troubleshooting#marketplace-claude-plugins-official-not-found)。若要控制外掛程式的安裝位置,或從 shell 而不是在 Claude Code 內執行安裝,請參閱[安裝外掛程式](/docs/zh-TW/plugins/install)。53在 VS Code 擴充功能或桌面應用程式中,請改為按照[安裝外掛程式](/docs/zh-TW/plugins/install#install-a-plugin)操作,而非執行此步驟。在終端機中,執行 `claude` 啟動 Claude Code,然後在其提示字元中輸入以下內容,將 `typescript-lsp` 替換為步驟 1 表格中為您的語言列出的外掛程式:
62 </Step>
63 54
64 <Step title="確認伺服器啟動">55```
65 語言伺服器在 Claude 首次編輯具有外掛程式副檔名之一的檔案時啟動。若要看到它運作,請要求 Claude 在該語言的檔案中引入型別錯誤,然後修復它。然後檢查對話框中的診斷行:56/plugin install typescript-lsp@claude-plugins-official
57```
66 58
67 * **出現診斷行**:在引入錯誤的編輯下方出現 `Found N new diagnostic issues in M files (ctrl+o to expand)` 表示伺服器已啟動。59確認訊息會說明外掛程式現在是否處於作用中或需要 `/reload-plugins`。如果安裝失敗並顯示 `Marketplace "claude-plugins-official" not found`,請參閱[該錯誤的疑難排解項目](/docs/zh-TW/plugins/troubleshooting#marketplace-claude-plugins-official-not-found)。若要控制外掛程式的安裝位置,或從 shell 而不是在 Claude Code 內執行安裝,請參閱[安裝外掛程式](/docs/zh-TW/plugins/install)。
68 * **未出現診斷行**:執行 `/plugin` 並開啟 **Errors** 標籤。讀取 `Executable not found in $PATH: "<binary>"` 的列會命名要安裝的二進位檔。如果標籤中沒有這樣的列,請參閱[疑難排解 code intelligence](#troubleshoot-code-intelligence)。
69 60
70 安裝遺漏的二進位檔後,Claude Code 會在 Claude 下次編輯相符檔案時重試。如果您將二進位檔安裝到不在您啟動 `claude` 的 shell 的 `PATH` 上的目錄中,請從它所在的 shell 啟動新工作階段。61**3. 確認伺服器啟動**
71 </Step>
72</Steps>
73 62
74<h2 id="see-what-claude-gains">63語言伺服器在 Claude 首次編輯具有外掛程式副檔名之一的檔案時啟動。若要看到它運作,請要求 Claude 在該語言的檔案中引入型別錯誤,然後修復它。然後檢查對話框中的診斷行:
75 查看 Claude 獲得的內容64
76</h2>65* **出現診斷行**:在引入錯誤的編輯下方出現 `Found N new diagnostic issues in M files (ctrl+o to expand)` 表示伺服器已啟動。
66* **未出現診斷行**:執行 `/plugin` 並開啟 **Errors** 標籤。讀取 `Executable not found in $PATH: "<binary>"` 的列會命名要安裝的二進位檔。如果標籤中沒有這樣的列,請參閱[疑難排解 code intelligence](#troubleshoot-code-intelligence)。
67
68安裝遺漏的二進位檔後,Claude Code 會在 Claude 下次編輯相符檔案時重試。如果您將二進位檔安裝到不在您啟動 `claude` 的 shell 的 `PATH` 上的目錄中,請從它所在的 shell 啟動新工作階段。
69
70## 查看 Claude 獲得的內容
77 71
78執行語言伺服器後,Claude 獲得診斷和程式碼導覽:72執行語言伺服器後,Claude 獲得診斷和程式碼導覽:
79 73
80* **編輯後的診斷**:每次 Claude 編輯或寫入伺服器處理的檔案時,Claude 都會獲得伺服器報告的錯誤和警告。它會看到它引入的型別錯誤、遺漏的匯入或語法錯誤,而無需執行編譯器。74* **編輯後的診斷**:每次 Claude 編輯或寫入伺服器處理的檔案時,Claude 都會獲得伺服器報告的錯誤和警告。它會看到它引入的型別錯誤、遺漏的匯入或語法錯誤,而無需執行編譯器。
81* **程式碼導覽**:Claude 獲得一個 `LSP` 工具,該工具透過伺服器查詢符號,而不是搜尋文字。該工具是唯讀的。有關 Claude 可以使用該工具查詢的內容以及權限如何應用於它,請參閱 [LSP 工具行為](/docs/zh-TW/tools-reference#lsp-tool-behavior)。75* **程式碼導覽**:Claude 獲得一個 `LSP` 工具,該工具透過伺服器查詢符號,而不是搜尋文字。該工具是唯讀的。有關 Claude 可以使用該工具查詢的內容以及權限如何應用於它,請參閱 [LSP 工具行為](/docs/zh-TW/tools-reference#lsp-tool-behavior)。
82 76
83<h3 id="read-the-diagnostics-yourself">77### 自己閱讀診斷
84 自己閱讀診斷
85</h3>
86 78
87Claude 編輯伺服器處理的檔案後,對話框只顯示 `Found N new diagnostic issues` 摘要。若要閱讀問題本身,請按 **Ctrl+O**。79Claude 編輯伺服器處理的檔案後,對話框只顯示 `Found N new diagnostic issues` 摘要。若要閱讀問題本身,請按 **Ctrl+O**。
88 80
89<h2 id="accept-or-dismiss-the-recommendation-dialog">81## 接受或關閉建議對話框
90 接受或關閉建議對話框
91</h2>
92 82
93如果語言伺服器二進位檔已在您的 `PATH` 上,但使用它的外掛程式未安裝,Claude Code 會在標題為 **LSP 外掛程式建議**的對話框中提供為您安裝外掛程式。83如果語言伺服器二進位檔已在您的 `PATH` 上,但使用它的外掛程式未安裝,Claude Code 會在標題為 **LSP 外掛程式建議**的對話框中提供為您安裝外掛程式。
94 84
95<h3 id="when-the-recommendation-dialog-appears">85### 建議對話框何時出現
96 建議對話框何時出現
97</h3>
98 86
99**LSP 外掛程式建議**對話框可在 Claude 編輯檔案後出現。這些條件決定它是否出現以及它提供哪個外掛程式:87**LSP 外掛程式建議**對話框可在 Claude 編輯檔案後出現。這些條件決定它是否出現以及它提供哪個外掛程式:
100 88
103* **每個工作階段一次**:對話框在一個工作階段中最多出現一次,針對 Claude 編輯的第一個相符檔案。91* **每個工作階段一次**:對話框在一個工作階段中最多出現一次,針對 Claude 編輯的第一個相符檔案。
104* **不適用於雲端工作階段**:當您的終端機連接到雲端工作階段(例如您使用 [`claude --cloud`](/docs/zh-TW/claude-code-on-the-web#from-terminal-to-cloud) 啟動的工作階段)時,對話框永遠不會出現。92* **不適用於雲端工作階段**:當您的終端機連接到雲端工作階段(例如您使用 [`claude --cloud`](/docs/zh-TW/claude-code-on-the-web#from-terminal-to-cloud) 啟動的工作階段)時,對話框永遠不會出現。
105 93
106<h3 id="respond-to-the-recommendation-dialog">94### 回應建議對話框
107 回應建議對話框
108</h3>
109 95
110**LSP 外掛程式建議**對話框會命名外掛程式並提供這些選擇:96**LSP 外掛程式建議**對話框會命名外掛程式並提供這些選擇:
111 97
116 102
117如果您未選擇選項,Claude Code 會在 30 秒後關閉它,並將其計為已忽略。計數會跨工作階段保留。在忽略五個對話框後,Claude Code 停止推薦外掛程式,與您選擇 **Disable all LSP recommendations** 相同。103如果您未選擇選項,Claude Code 會在 30 秒後關閉它,並將其計為已忽略。計數會跨工作階段保留。在忽略五個對話框後,Claude Code 停止推薦外掛程式,與您選擇 **Disable all LSP recommendations** 相同。
118 104
119<h3 id="turn-recommendations-back-on">105### 重新開啟建議
120 重新開啟建議
121</h3>
122 106
123**LSP 外掛程式建議**對話框在您選擇 **Disable all LSP recommendations** 或忽略它五次後停止出現。107**LSP 外掛程式建議**對話框在您選擇 **Disable all LSP recommendations** 或忽略它五次後停止出現。
124 108
125* **已停用或忽略五次**:若要在任一情況下重新開啟它,請從 `~/.claude.json`(Claude Code 自己的設定檔)中移除 `lspRecommendationDisabled` 和 `lspRecommendationIgnoredCount` 鍵。109* **已停用或忽略五次**:若要在任一情況下重新開啟它,請從 `~/.claude.json`(Claude Code 自己的設定檔)中移除 `lspRecommendationDisabled` 和 `lspRecommendationIgnoredCount` 鍵。
126* **永不為此外掛程式**:如果您選擇了 **Never for this plugin** 並希望再次提供該外掛程式,請從同一檔案中的 `lspRecommendationNeverPlugins` 列表中移除其 `name@marketplace` ID。110* **永不為此外掛程式**:如果您選擇了 **Never for this plugin** 並希望再次提供該外掛程式,請從同一檔案中的 `lspRecommendationNeverPlugins` 列表中移除其 `name@marketplace` ID。
127 111
128<h2 id="troubleshoot-code-intelligence">112## 疑難排解 code intelligence
129 疑難排解 code intelligence
130</h2>
131 113
132外掛程式疑難排解頁面涵蓋 code intelligence 外掛程式特定的症狀,位於[語言伺服器不啟動、使用過多記憶體或報告錯誤診斷](/docs/zh-TW/plugins/troubleshooting#language-server-doesnt-start)下:114外掛程式疑難排解頁面涵蓋 code intelligence 外掛程式特定的症狀,位於[語言伺服器不啟動、使用過多記憶體或報告錯誤診斷](/docs/zh-TW/plugins/troubleshooting#language-server-doesnt-start)下:
133 115
135* **高記憶體使用量**:當伺服器索引專案時,記憶體使用量會增加。117* **高記憶體使用量**:當伺服器索引專案時,記憶體使用量會增加。
136* **monorepo 中的誤判診斷**:診斷報告匯入為未解決,但實際上已解決。118* **monorepo 中的誤判診斷**:診斷報告匯入為未解決,但實際上已解決。
137 119
138<h2 id="add-a-language-without-an-official-plugin">120## 新增沒有官方外掛程式的語言
139 新增沒有官方外掛程式的語言
140</h2>
141 121
142如果您的語言不在[官方外掛程式表格](#install-a-code-intelligence-plugin)中,您仍然可以連接語言伺服器。122如果您的語言不在[官方外掛程式表格](#install-a-code-intelligence-plugin)中,您仍然可以連接語言伺服器。
143 123
146 126
147有關檔案的欄位和實際範例,請參閱[外掛程式元件中的 LSP 伺服器](/docs/zh-TW/plugins/components#lsp-servers)。127有關檔案的欄位和實際範例,請參閱[外掛程式元件中的 LSP 伺服器](/docs/zh-TW/plugins/components#lsp-servers)。
148 128
149<h2 id="next-steps">129## 後續步驟
150 後續步驟
151</h2>
152 130
153* [外掛程式元件中的 LSP 伺服器](/docs/zh-TW/plugins/components#lsp-servers):為沒有官方外掛程式的語言伺服器撰寫 `.lsp.json`131* [外掛程式元件中的 LSP 伺服器](/docs/zh-TW/plugins/components#lsp-servers):為沒有官方外掛程式的語言伺服器撰寫 `.lsp.json`
154* [安裝和管理外掛程式](/docs/zh-TW/plugins/install):範圍、更新和解除安裝132* [安裝和管理外掛程式](/docs/zh-TW/plugins/install):範圍、更新和解除安裝