Repository: shader-slang/slang
File: source/slang/slang-language-server.cpp (C++)

Code before:
        }
    }
    else if (auto includeDeclBase = as<IncludeDeclBase>(leafNode))
    {
        auto location =
            getModuleLoc(version->linkage->getSourceManager(), includeDeclBase->fileDecl);
        if (location.pathInfo.hasFoundPath())
        {
            locations.add(LocationResult{location, 0});
        }
    }
    if (locations.getCount() == 0)
    {
        return std::nullopt;
    }
    else
    {
        List<Location> results;
        for (auto loc : locations)
        {
            Location result;
            if (File::exists(loc.loc.pathInfo.foundPath))
            {
                // Canonicalize the path to ensure we always use absolute paths in URIs
                String canonicalFoundPath = loc.loc.pathInfo.foundPath;
                if (SLANG_SUCCEEDED(Path::getCanonical(canonicalFoundPath, canonicalFoundPath)))
                {
                    result.uri = URI::fromLocalFilePath(canonicalFoundPath.getUnownedSlice()).uri;
                }
                else
                {
                    // If canonicalization fails, use the original path
                    result.uri =
                        URI::fromLocalFilePath(loc.loc.pathInfo.foundPath.getUnownedSlice()).uri;
                }
            }
            else if (loc.loc.pathInfo.getName() == "core" || loc.loc.pathInfo.getName() == "glsl")
            {
                result.uri = StringBuilder() << "slang-synth://" << loc.loc.pathInfo.getName()
                                             << "/" << loc.loc.pathInfo.getName() << ".builtin";
            }
            if (result.uri.getLength() != 0)
            {
                doc->oneBasedUTF8LocToZeroBasedUTF16Loc(
                    loc.loc.line,
                    loc.loc.column,
                    result.range.start.line,
                    result.range.start.character);
                result.range.end = result.range.start;
                result.range.end.character += loc.length;
                results.add(result);

Review comment (suggestion):
It doesn't feel safe to use the same object as an input and an output at the same time, although the implementation of getCanonical appears to be safe for this case.
I prefer it to be more like,
```
String canonicalFoundPath;
if (SLANG_SUCCEEDED(Path::getCanonical(loc.loc.pathInfo.foundPath, canonicalFoundPath)))
```

Code after:
        }
    }
    else if (auto includeDeclBase = as<IncludeDeclBase>(leafNode))
    {
        auto location =
            getModuleLoc(version->linkage->getSourceManager(), includeDeclBase->fileDecl);
        if (location.pathInfo.hasFoundPath())
        {
            locations.add(LocationResult{location, 0});
        }
    }
    if (locations.getCount() == 0)
    {
        return std::nullopt;
    }
    else
    {
        List<Location> results;
        for (auto loc : locations)
        {
            Location result;
            if (File::exists(loc.loc.pathInfo.foundPath))
            {
                // Canonicalize the path to ensure we always use absolute paths in URIs
                String canonicalFoundPath;
                if (SLANG_SUCCEEDED(
                        Path::getCanonical(loc.loc.pathInfo.foundPath, canonicalFoundPath)))
                {
                    result.uri = URI::fromLocalFilePath(canonicalFoundPath.getUnownedSlice()).uri;
                }
                else
                {
                    // If canonicalization fails, use the original path
                    result.uri =
                        URI::fromLocalFilePath(loc.loc.pathInfo.foundPath.getUnownedSlice()).uri;
                }
            }
            else if (loc.loc.pathInfo.getName() == "core" || loc.loc.pathInfo.getName() == "glsl")
            {
                result.uri = StringBuilder() << "slang-synth://" << loc.loc.pathInfo.getName()
                                             << "/" << loc.loc.pathInfo.getName() << ".builtin";
            }
            if (result.uri.getLength() != 0)
            {
                doc->oneBasedUTF8LocToZeroBasedUTF16Loc(
                    loc.loc.line,
                    loc.loc.column,
                    result.range.start.line,
                    result.range.start.character);
                result.range.end = result.range.start;
                result.range.end.character += loc.length;