Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to resolve resource on Windows #2212

Closed
Tracked by #2062
Cellule opened this issue Feb 27, 2022 · 3 comments · Fixed by #2214
Closed
Tracked by #2062

Unable to resolve resource on Windows #2212

Cellule opened this issue Feb 27, 2022 · 3 comments · Fixed by #2214
Labels
lsp-server graphql-language-service-server

Comments

@Cellule
Copy link
Contributor

Cellule commented Feb 27, 2022

Original fix #1715
Regression from #2072
Related graphql/vscode-graphql#254

image

After some digging, I've confirmed that the bad path is indeed present in the GraphQLCache for the type.
Supposedly the uri is wrong when caching the schema (I wasn't able to debug at that stage because I'm attaching too late to the process)

async _cacheSchemaFile(
uri: UnnormalizedTypeDefPointer,
project: GraphQLProjectConfig,
) {
uri = uri.toString();
const isFileUri = existsSync(uri);
let version = 1;
if (isFileUri) {
const schemaUri = URI.parse(path.join(project.dirpath, uri)).toString();
const schemaDocument = this._getCachedDocument(schemaUri);
if (schemaDocument) {
version = schemaDocument.version++;
}
const schemaText = readFileSync(uri, { encoding: 'utf-8' });
this._cacheSchemaText(schemaUri, schemaText, version);
}
}

I suspect some vscode-uri.URI.parse(uri).toString() should use vscode-uri.URI.parse(uri).fsPath instead? but my initial attempt failed miserably and I'm a little out of my comfort zone at this point

@acao
Copy link
Member

acao commented Feb 27, 2022

Yes, I had thought we had replaced all of these old URI.parse() statements my bad.

@Cellule
Copy link
Contributor Author

Cellule commented Feb 27, 2022

Alright I gave it another try, from #2072 I put back all the replaced occurrences of pathToFileURL and it works

I think the problem is because it shouldn't be using vscode-uri.URI.parse on filesystem paths, it should only be used on fileURI

I get the following on Windows

> require("vscode-uri").URI.parse("C:\\projects\\graphiql\\packages\\graphql-language-service-server").toString()
'C:%5Cprojects%5Cgraphiql%5Cpackages%5Cgraphql-language-service-server'

> require("url").pathToFileURL("C:\\projects\\graphiql\\packages\\graphql-language-service-server").toString()
'file:///C:/projects/graphiql/packages/graphql-language-service-server

@Cellule
Copy link
Contributor Author

Cellule commented Feb 27, 2022

Actually, it looks like the proper fix is to use vscode-uri.URI.file().toString() in place where we have a filesystem path
As shown here https://github.com/microsoft/vscode-uri
image

> require("vscode-uri").URI.file("C:\\projects\\graphiql\\packages\\graphql-language-service-server").toString()
'file:///c%3A/projects/graphiql/packages/graphql-language-service-server'

I tried it real quick and it seems to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lsp-server graphql-language-service-server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants