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

Go to References - Where Imports Used #1491

Merged
merged 18 commits into from May 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/language-server/package.json
Expand Up @@ -6,6 +6,7 @@
"typings": "dist/src/index",
"scripts": {
"test": "cross-env TS_NODE_TRANSPILE_ONLY=true mocha --require ts-node/register \"test/**/*.ts\" --exclude \"test/**/*.d.ts\"",
"test2": "cross-env TS_NODE_TRANSPILE_ONLY=true mocha --require ts-node/register \"test/**/FindFileReferencesProvider.test.ts\" --exclude \"test/**/*.d.ts\"",
Jojoshua marked this conversation as resolved.
Show resolved Hide resolved
"build": "tsc",
"prepublishOnly": "npm run build",
"watch": "tsc -w"
Expand Down
@@ -0,0 +1,68 @@
import * as assert from 'assert';
import * as path from 'path';
import ts from 'typescript';
import { Location, Position, Range } from 'vscode-languageserver';
import { Document, DocumentManager } from '../../../../src/lib/documents';
import { LSConfigManager } from '../../../../src/ls-config';
import { FindFileReferencesProviderImpl } from '../../../../src/plugins/typescript/features/FindFileReferencesProvider';
import { LSAndTSDocResolver } from '../../../../src/plugins/typescript/LSAndTSDocResolver';
import { pathToUrl } from '../../../../src/utils';

const testDir = path.join(__dirname, '..');

function test(useNewTransformation: boolean) {
return () => {
function getFullPath(filename: string) {
return path.join(testDir, 'testfiles', filename);
}
function getUri(filename: string) {
const filePath = path.join(testDir, 'testfiles', filename);
return pathToUrl(filePath);
}

function setup(filename: string) {
const docManager = new DocumentManager(
(textDocument) => new Document(textDocument.uri, textDocument.text)
);
const lsConfigManager = new LSConfigManager();
lsConfigManager.update({ svelte: { useNewTransformation } });
const lsAndTsDocResolver = new LSAndTSDocResolver(
docManager,
[testDir],
lsConfigManager
);
const provider = new FindFileReferencesProviderImpl(lsAndTsDocResolver);
Jojoshua marked this conversation as resolved.
Show resolved Hide resolved
const document = openDoc(filename);
return { provider, document };

function openDoc(filename: string) {
const filePath = getFullPath(filename);
const doc = docManager.openDocument(<any>{
uri: pathToUrl(filePath),
text: ts.sys.readFile(filePath) || ''
});
return doc;
}
}

async function test() {
const { provider, document } = setup('find-file-references-child.svelte');

const results = await provider.fileReferences(document.uri.toString());
Jojoshua marked this conversation as resolved.
Show resolved Hide resolved
const expectedResults = [
Location.create(
getUri('find-file-references-parent.svelte'),
Range.create(Position.create(1, 37), Position.create(1, 72))
)
];

assert.deepStrictEqual(results, expectedResults);
}

it('finds file references', async () => {
await test();
});
};
}

describe('FindFileReferencesProvider', test(true));
@@ -0,0 +1,6 @@
<script>
const findMe = true;
if (findMe) {
findMe;
}
</script>
@@ -0,0 +1,10 @@
<script>
import FindFileReferencesChild from "./find-file-references-child.svelte";

const findMe = true;
if (findMe) {
findMe;
}
</script>

<FindFileReferencesChild></FindFileReferencesChild>