Skip to content

Commit

Permalink
fix: Fix issues with UNC (#3925)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Dec 15, 2024
1 parent 2d0b0a1 commit a673230
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/__utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"watch": "tsc -p . --watch"
},
"dependencies": {
"@cspell/url": "^8.17.0",
"vscode-uri": "^3.0.8"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/__utils/src/uriHelper.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Validate uriHelper', () => {
${new URL('http://www.streetsidesoftware.nl')} | ${'http://www.streetsidesoftware.nl/'}
${'/path/to/file.txt'} | ${Uri.parse(pathToFileURL('/path/to/file.txt').toString()).toString()}
${'path/to/file.txt'} | ${Uri.parse(pathToFileURL('path/to/file.txt').toString()).toString()}
${''} | ${Uri.parse(pathToFileURL('').toString()).toString()}
${''} | ${Uri.parse(pathToFileURL('./').toString()).toString()}
`('toUri $uri', ({ uri, expected }) => {
expect(toUri(uri).toString()).toBe(expected.toString());
});
Expand Down
4 changes: 2 additions & 2 deletions packages/__utils/src/uriHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pathToFileURL } from 'url';
import { toFileURL } from '@cspell/url';
import { URI as Uri, Utils as UriUtils } from 'vscode-uri';

export const supportedSchemes = [
Expand Down Expand Up @@ -41,7 +41,7 @@ export function toFileUri(uri: undefined | null): undefined;
export function toFileUri(uri: string | Uri | URL | undefined | null): Uri | undefined;
export function toFileUri(uri: string | Uri | URL | undefined | null): Uri | undefined {
if (typeof uri === 'string') {
return regExpIsUri.test(uri) ? Uri.parse(uri) : Uri.parse(pathToFileURL(uri).toString());
return regExpIsUri.test(uri) ? Uri.parse(uri) : Uri.parse(toFileURL(uri).toString());
}
if (!uri) return undefined;
if (uri instanceof URL) {
Expand Down
1 change: 1 addition & 0 deletions packages/_server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@cspell/cspell-bundled-dicts": "^8.17.0",
"@cspell/cspell-pipe": "^8.17.0",
"@cspell/cspell-types": "^8.17.0",
"@cspell/url": "^8.17.0",
"@internal/common-utils": "file:../__utils",
"cspell-config-lib": "^8.17.0",
"cspell-gitignore": "^8.17.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/_server/src/config/documentSettings.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
Pattern,
RegExpPatternDefinition,
} from '@cspell/cspell-types';
import { toFileURL } from '@cspell/url';
import { createEmitter, setIfDefined } from '@internal/common-utils';
import type { AutoLoadCache, LazyValue } from '@internal/common-utils/autoLoad';
import { createAutoLoadCache, createLazyValue } from '@internal/common-utils/autoLoad';
Expand All @@ -28,7 +29,6 @@ import {
mergeSettings,
searchForConfig,
} from 'cspell-lib';
import { pathToFileURL } from 'url';
import type { DisposableClassic } from 'utils-disposables';
import type { Connection, WorkspaceFolder } from 'vscode-languageserver/node.js';
import { URI as Uri, Utils as UriUtils } from 'vscode-uri';
Expand Down Expand Up @@ -271,7 +271,7 @@ export class DocumentSettings {
log('importSettings');
const importPaths = [...this.configsToImport].sort();
const loader = getDefaultConfigLoader();
const cfg = loader.createCSpellConfigFile(pathToFileURL(fileConfigsToImport), {
const cfg = loader.createCSpellConfigFile(toFileURL(fileConfigsToImport), {
name: 'VS Code Imports',
import: importPaths,
readonly: true,
Expand Down Expand Up @@ -334,7 +334,7 @@ export class DocumentSettings {
// url = toPathURL(this.#rootHref || defaultRootUri);
// }
if (url.protocol === 'file:') {
url = pathToFileURL('/');
url = toFileURL('/', url);
} else {
url = new URL('/', url);
}
Expand Down Expand Up @@ -426,7 +426,7 @@ export class DocumentSettings {
await this.determineIsTrusted();
return await this.__fetchSettingsForUri(docUri);
} catch (_e) {
console.error('fetchSettingsForUri: %s %s', docUri, _e);
console.error('fetchSettingsForUri: %s %o', docUri, _e);
return {
uri: docUri || '',
vscodeSettings: { cSpell: {} },
Expand Down
5 changes: 3 additions & 2 deletions packages/_server/src/config/urlUtil.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fileURLToPath, pathToFileURL } from 'node:url';
import { fileURLToPath } from 'node:url';

import { toFileURL } from '@cspell/url';
import { isUrlLike as _isUrlLike } from 'cspell-io';
import { URI as Uri } from 'vscode-uri';

Expand Down Expand Up @@ -121,7 +122,7 @@ export function uriToGlobRoot(uri: UrlLike): string {

export function uriToUrl(uri: UrlLike): Readonly<URL> {
if (uri instanceof URL) return uri;
uri = typeof uri === 'string' && !isUriLike(uri) ? pathToFileURL(uri) : uri;
uri = typeof uri === 'string' && !isUriLike(uri) ? toFileURL(uri) : uri;
const href = typeof uri === 'string' ? uri : uri.toString();
return normalizeWindowsUrl(new URL(href));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/applyCorrections.mts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ interface UseRefInfo {
export async function handleApplyLsTextEdits(uri: string, documentVersion: number, edits: LsTextEdit[]): Promise<void> {
const converter = di.get('client').client.protocol2CodeConverter;

console.warn('handleApplyTextEdits %o', { uri, documentVersion, edits });
// console.warn('handleApplyTextEdits %o', { uri, documentVersion, edits });

return applyTextEditsWithRename(uri, cvtLsTextEdits(converter, edits), documentVersion);
}
Expand Down

0 comments on commit a673230

Please sign in to comment.