workspaceFile -> workspacePath

This commit is contained in:
Matt Bierner 2022-03-30 15:14:15 -07:00
parent f3cb3510b8
commit 982a353285
No known key found for this signature in database
GPG key ID: 099C331567E11888
3 changed files with 34 additions and 34 deletions

View file

@ -10,7 +10,7 @@ import { MdLinkProvider } from '../languageFeatures/documentLinkProvider';
import { MdPathCompletionProvider } from '../languageFeatures/pathCompletions';
import { InMemoryDocument } from '../util/inMemoryDocument';
import { createNewMarkdownEngine } from './engine';
import { CURSOR, getCursorPositions, joinLines, noopToken, workspaceFile } from './util';
import { CURSOR, getCursorPositions, joinLines, noopToken, workspacePath } from './util';
function getCompletionsAtCursor(resource: vscode.Uri, fileContents: string) {
@ -33,12 +33,12 @@ suite('Markdown path completion provider', () => {
});
test('Should not return anything when triggered in empty doc', async () => {
const completions = await getCompletionsAtCursor(workspaceFile('new.md'), `${CURSOR}`);
const completions = await getCompletionsAtCursor(workspacePath('new.md'), `${CURSOR}`);
assert.strictEqual(completions.length, 0);
});
test('Should return anchor completions', async () => {
const completions = await getCompletionsAtCursor(workspaceFile('new.md'), joinLines(
const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines(
`[](#${CURSOR}`,
``,
`# A b C`,
@ -51,7 +51,7 @@ suite('Markdown path completion provider', () => {
});
test('Should not return suggestions for http links', async () => {
const completions = await getCompletionsAtCursor(workspaceFile('new.md'), joinLines(
const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines(
`[](http:${CURSOR}`,
``,
`# http`,
@ -63,7 +63,7 @@ suite('Markdown path completion provider', () => {
});
test('Should return relative path suggestions', async () => {
const completions = await getCompletionsAtCursor(workspaceFile('new.md'), joinLines(
const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines(
`[](${CURSOR}`,
``,
`# A b C`,
@ -75,7 +75,7 @@ suite('Markdown path completion provider', () => {
});
test('Should return relative path suggestions using ./', async () => {
const completions = await getCompletionsAtCursor(workspaceFile('new.md'), joinLines(
const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines(
`[](./${CURSOR}`,
``,
`# A b C`,
@ -87,7 +87,7 @@ suite('Markdown path completion provider', () => {
});
test('Should return absolute path suggestions using /', async () => {
const completions = await getCompletionsAtCursor(workspaceFile('sub', 'new.md'), joinLines(
const completions = await getCompletionsAtCursor(workspacePath('sub', 'new.md'), joinLines(
`[](/${CURSOR}`,
``,
`# A b C`,
@ -100,7 +100,7 @@ suite('Markdown path completion provider', () => {
});
test('Should return anchor suggestions in other file', async () => {
const completions = await getCompletionsAtCursor(workspaceFile('sub', 'new.md'), joinLines(
const completions = await getCompletionsAtCursor(workspacePath('sub', 'new.md'), joinLines(
`[](/b.md#${CURSOR}`,
));
@ -109,7 +109,7 @@ suite('Markdown path completion provider', () => {
});
test('Should reference links for current file', async () => {
const completions = await getCompletionsAtCursor(workspaceFile('sub', 'new.md'), joinLines(
const completions = await getCompletionsAtCursor(workspacePath('sub', 'new.md'), joinLines(
`[][${CURSOR}`,
``,
`[ref-1]: bla`,
@ -122,7 +122,7 @@ suite('Markdown path completion provider', () => {
});
test('Should complete headers in link definitions', async () => {
const completions = await getCompletionsAtCursor(workspaceFile('sub', 'new.md'), joinLines(
const completions = await getCompletionsAtCursor(workspacePath('sub', 'new.md'), joinLines(
`# a B c`,
`# x y Z`,
`[ref-1]: ${CURSOR}`,
@ -133,7 +133,7 @@ suite('Markdown path completion provider', () => {
});
test('Should complete relative paths in link definitions', async () => {
const completions = await getCompletionsAtCursor(workspaceFile('new.md'), joinLines(
const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines(
`# a B c`,
`[ref-1]: ${CURSOR}`,
));
@ -144,7 +144,7 @@ suite('Markdown path completion provider', () => {
});
test('Should escape spaces in path names', async () => {
const completions = await getCompletionsAtCursor(workspaceFile('new.md'), joinLines(
const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines(
`[](./sub/${CURSOR})`
));
@ -152,7 +152,7 @@ suite('Markdown path completion provider', () => {
});
test('Should complete paths for path with encoded spaces', async () => {
const completions = await getCompletionsAtCursor(workspaceFile('new.md'), joinLines(
const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines(
`[](./sub%20with%20space/${CURSOR})`
));
@ -160,7 +160,7 @@ suite('Markdown path completion provider', () => {
});
test('Should complete definition path for path with encoded spaces', async () => {
const completions = await getCompletionsAtCursor(workspaceFile('new.md'), joinLines(
const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines(
`[def]: ./sub%20with%20space/${CURSOR}`
));

View file

@ -13,7 +13,7 @@ import { InMemoryDocument } from '../util/inMemoryDocument';
import { MdWorkspaceContents } from '../workspaceContents';
import { createNewMarkdownEngine } from './engine';
import { InMemoryWorkspaceMarkdownDocuments } from './inMemoryWorkspace';
import { joinLines, noopToken, workspaceFile } from './util';
import { joinLines, noopToken, workspacePath } from './util';
function getReferences(doc: InMemoryDocument, pos: vscode.Position, workspaceContents: MdWorkspaceContents) {
@ -36,7 +36,7 @@ function assertReferencesEqual(actualRefs: readonly vscode.Location[], ...expect
suite('markdown: find all references', () => {
test('Should not return references when not on header or link', async () => {
const doc = new InMemoryDocument(workspaceFile('doc.md'), joinLines(
const doc = new InMemoryDocument(workspacePath('doc.md'), joinLines(
`# abc`,
``,
`[link 1](#abc)`,
@ -54,7 +54,7 @@ suite('markdown: find all references', () => {
});
test('Should find references from header within same file', async () => {
const uri = workspaceFile('doc.md');
const uri = workspacePath('doc.md');
const doc = new InMemoryDocument(uri, joinLines(
`# abc`,
``,
@ -71,7 +71,7 @@ suite('markdown: find all references', () => {
});
test('Should find references using normalized slug', async () => {
const doc = new InMemoryDocument(workspaceFile('doc.md'), joinLines(
const doc = new InMemoryDocument(workspacePath('doc.md'), joinLines(
`# a B c`,
`[simple](#a-b-c)`,
`[start underscore](#_a-b-c)`,
@ -101,9 +101,9 @@ suite('markdown: find all references', () => {
});
test('Should find references from header across files', async () => {
const docUri = workspaceFile('doc.md');
const other1Uri = workspaceFile('sub', 'other.md');
const other2Uri = workspaceFile('other2.md');
const docUri = workspacePath('doc.md');
const other1Uri = workspacePath('sub', 'other.md');
const other2Uri = workspacePath('other2.md');
const doc = new InMemoryDocument(docUri, joinLines(
`# abc`,
@ -133,7 +133,7 @@ suite('markdown: find all references', () => {
});
test('Should find references from header to link definitions ', async () => {
const uri = workspaceFile('doc.md');
const uri = workspacePath('doc.md');
const doc = new InMemoryDocument(uri, joinLines(
`# abc`,
``,
@ -148,7 +148,7 @@ suite('markdown: find all references', () => {
});
test('Should find references from link within same file', async () => {
const uri = workspaceFile('doc.md');
const uri = workspacePath('doc.md');
const doc = new InMemoryDocument(uri, joinLines(
`# abc`,
``,
@ -166,9 +166,9 @@ suite('markdown: find all references', () => {
});
test('Should find references from link across files', async () => {
const docUri = workspaceFile('doc.md');
const other1Uri = workspaceFile('sub', 'other.md');
const other2Uri = workspaceFile('other2.md');
const docUri = workspacePath('doc.md');
const other1Uri = workspacePath('sub', 'other.md');
const other2Uri = workspacePath('other2.md');
const doc = new InMemoryDocument(docUri, joinLines(
`# abc`,
@ -200,8 +200,8 @@ suite('markdown: find all references', () => {
});
test('Should find references from link across files when triggered on link without file extension', async () => {
const docUri = workspaceFile('doc.md');
const other1Uri = workspaceFile('sub', 'other.md');
const docUri = workspacePath('doc.md');
const other1Uri = workspacePath('sub', 'other.md');
const doc = new InMemoryDocument(docUri, joinLines(
`[with ext](./sub/other#header)`,
@ -225,8 +225,8 @@ suite('markdown: find all references', () => {
});
test('Should include header references when triggered on file link', async () => {
const docUri = workspaceFile('doc.md');
const otherUri = workspaceFile('sub', 'other.md');
const docUri = workspacePath('doc.md');
const otherUri = workspacePath('sub', 'other.md');
const doc = new InMemoryDocument(docUri, joinLines(
`[with ext](./sub/other)`,
@ -252,7 +252,7 @@ suite('markdown: find all references', () => {
suite('Reference links', () => {
test('Should find reference links within file', async () => {
const docUri = workspaceFile('doc.md');
const docUri = workspacePath('doc.md');
const doc = new InMemoryDocument(docUri, joinLines(
`[link 1][abc]`,
``,
@ -267,7 +267,7 @@ suite('markdown: find all references', () => {
});
test('Should not find reference links across files', async () => {
const docUri = workspaceFile('doc.md');
const docUri = workspacePath('doc.md');
const doc = new InMemoryDocument(docUri, joinLines(
`[link 1][abc]`,
``,
@ -276,7 +276,7 @@ suite('markdown: find all references', () => {
const refs = await getReferences(doc, new vscode.Position(0, 12), new InMemoryWorkspaceMarkdownDocuments([
doc,
new InMemoryDocument(workspaceFile('other.md'), joinLines(
new InMemoryDocument(workspacePath('other.md'), joinLines(
`[link 1][abc]`,
``,
`[abc]: https://example.com?bad`,

View file

@ -32,6 +32,6 @@ export function getCursorPositions(contents: string, doc: InMemoryDocument): vsc
return positions;
}
export function workspaceFile(...segments: string[]): vscode.Uri {
export function workspacePath(...segments: string[]): vscode.Uri {
return vscode.Uri.joinPath(vscode.workspace.workspaceFolders![0].uri, ...segments);
}