> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/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 = <<