package grammar import ( "fmt" "net/url" "os" "path/filepath" "strconv" "strings" ) // pathToURI turns an editor file path into an LSP document URI. Unnamed buffers // (empty path) get a stable synthetic URI so harper still checks them. func pathToURI(path string) string { if strings.TrimSpace(path) == "" { return "file:///glint-untitled.md" } abs := path if p, err := filepath.Abs(path); err == nil { abs = p } return "file://" + (&url.URL{Path: abs}).EscapedPath() } // osGetwd returns the working directory for the initialize rootUri, falling back // to the temp dir so a missing cwd never breaks startup. func osGetwd() string { if wd, err := os.Getwd(); err == nil { return wd } return os.TempDir() } func itoa(n int) string { return strconv.Itoa(n) } // codeString renders an LSP diagnostic code, which may be a string or a number, // as a string. func codeString(code any) string { switch v := code.(type) { case string: return v case float64: return strconv.FormatFloat(v, 'f', -1, 64) case nil: return "" default: return fmt.Sprint(v) } }