> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # LSP 檢查 **新增於:** `@mastra/core@1.1.0` LSP 檢查為以 Workspace 為基礎的 Agent 提供語義程式碼智能。當你在 Workspace 啟用 LSP,Agent 便可檢查支援檔案中的符號,以擷取懸停資訊及跳至定義,亦可尋找實作。 ## 何時使用 LSP 檢查 當 Agent 需要理解程式碼語義,而不只是純文字搜尋時,請使用 LSP 檢查: - 檢查任何支援語言中的符號及其推斷類型 - 在編輯相關程式碼前,找出符號的宣告位置 - 探索整個程式碼庫中的實作,毋須手動追查每個檔案 - 配合 `view` 和 `search_content` 使用語義檢查,加快導覽速度 - 透過[註冊自訂語言伺服器](#custom-language-servers),為其他語言加入 LSP 支援 ## 基本用法 將 `lsp: true` 設定於 Workspace,以啟用 LSP: ```typescript import { Workspace, LocalFilesystem, LocalSandbox } from '@mastra/core/workspace' const workspace = new Workspace({ filesystem: new LocalFilesystem({ basePath: './workspace' }), sandbox: new LocalSandbox({ workingDirectory: './workspace' }), lsp: true, }) ``` 使用此設定時,Workspace 會在已設定的檔案系統及 Sandbox Tool 之外,註冊預設的 LSP 檢查 Tool。 ## Agent Tool 啟用 LSP 後,Workspace 預設會公開 `mastra_workspace_lsp_inspect`。 ```json { "path": "/absolute/path/to/file.ts", "line": 10, "match": "const foo = <<