-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(language-server): cannot restore uri from untitled document fileN…
…ame (#135)
- Loading branch information
1 parent
e273f09
commit 552b907
Showing
4 changed files
with
44 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { URI } from 'vscode-uri'; | ||
|
||
export function uriToFileName(uri: string) { | ||
const parsed = URI.parse(uri); | ||
if (parsed.scheme === 'file') { | ||
return parsed.fsPath.replace(/\\/g, '/'); | ||
} | ||
return `${parsed.scheme}@@${parsed.authority}@@${parsed.path}`; | ||
} | ||
|
||
export function fileNameToUri(fileName: string) { | ||
if (fileName.includes('@@')) { | ||
const parts = fileName.split('@@'); | ||
return URI.from({ | ||
scheme: parts[0], | ||
authority: parts[1], | ||
path: parts[2], | ||
}).toString(); | ||
} | ||
return URI.file(fileName).toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
import { URI } from 'vscode-uri'; | ||
import { fileNameToUri, uriToFileName } from '../lib/uri'; | ||
|
||
describe('URI', () => { | ||
|
||
test('recoverable', () => { | ||
|
||
const cases = [ | ||
'file:///a/b/c', | ||
'test://test/test.html', | ||
'file:///c:/a/b/c', | ||
'file:///C:/a/b/c', | ||
'untitled:Untitled-1', | ||
]; | ||
|
||
for (const uri of cases) { | ||
expect(fileNameToUri(uriToFileName(uri))).toBe(URI.parse(uri).toString()); | ||
} | ||
}); | ||
}); |