detectShadowBuild checks if a shadow build directory exists and is valid. Returns the shadow directory path if found, empty string otherwise. A valid shadow build has: shadow directory exists, contains go.mod, and shadow build is enabled in config.
(workspacePath string)
| 189 | // Returns the shadow directory path if found, empty string otherwise. |
| 190 | // A valid shadow build has: shadow directory exists, contains go.mod, and shadow build is enabled in config. |
| 191 | func (s *Server) detectShadowBuild(workspacePath string) string { |
| 192 | // Load config from workspace to check settings |
| 193 | cfg, err := config.LoadFromDir(workspacePath) |
| 194 | if err != nil { |
| 195 | s.config.Logger.Warnf("Failed to load config from %s: %v", workspacePath, err) |
| 196 | return "" |
| 197 | } |
| 198 | |
| 199 | // Store the config for later use |
| 200 | s.dingoConfig = cfg |
| 201 | // Update cache config for shadow build path calculations |
| 202 | s.mapCache.SetConfig(cfg) |
| 203 | |
| 204 | // Check if shadow build is enabled |
| 205 | if !cfg.Build.Shadow { |
| 206 | s.config.Logger.Debugf("Shadow build disabled in config") |
| 207 | return "" |
| 208 | } |
| 209 | |
| 210 | // Determine shadow directory name (default: "build") |
| 211 | shadowDirName := cfg.Build.OutDir |
| 212 | if shadowDirName == "" { |
| 213 | shadowDirName = "build" |
| 214 | } |
| 215 | |
| 216 | shadowPath := filepath.Join(workspacePath, shadowDirName) |
| 217 | |
| 218 | // Check if shadow directory exists |
| 219 | info, err := os.Stat(shadowPath) |
| 220 | if err != nil || !info.IsDir() { |
| 221 | s.config.Logger.Debugf("Shadow directory not found: %s", shadowPath) |
| 222 | return "" |
| 223 | } |
| 224 | |
| 225 | // Check if go.mod exists in shadow directory |
| 226 | goModPath := filepath.Join(shadowPath, "go.mod") |
| 227 | if _, err := os.Stat(goModPath); err != nil { |
| 228 | s.config.Logger.Debugf("No go.mod in shadow directory: %s", shadowPath) |
| 229 | return "" |
| 230 | } |
| 231 | |
| 232 | return shadowPath |
| 233 | } |
| 234 | |
| 235 | // SetConn stores the connection and context in the server (thread-safe) |
| 236 | func (s *Server) SetConn(conn jsonrpc2.Conn, ctx context.Context) { |
no test coverage detected