volar-service-typescript 0.0.20 → 0.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  import type * as vscode from '@volar/language-service';
2
2
  import type { SharedContext } from '../types';
3
- export declare function register(ctx: SharedContext): (uri: string, position: vscode.Position) => vscode.Location[];
3
+ export declare function register(ctx: SharedContext): (uri: string, position: vscode.Position, referenceContext: vscode.ReferenceContext) => vscode.Location[];
4
4
  //# sourceMappingURL=references.d.ts.map
@@ -4,16 +4,31 @@ exports.register = void 0;
4
4
  const shared_1 = require("../shared");
5
5
  const transforms_1 = require("../utils/transforms");
6
6
  function register(ctx) {
7
- return (uri, position) => {
7
+ return (uri, position, referenceContext) => {
8
8
  const document = ctx.getTextDocument(uri);
9
9
  if (!document)
10
10
  return [];
11
11
  const fileName = ctx.env.uriToFileName(document.uri);
12
12
  const offset = document.offsetAt(position);
13
- const entries = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getReferencesAtPosition(fileName, offset));
14
- if (!entries)
13
+ const references = (0, shared_1.safeCall)(() => ctx.typescript.languageService.findReferences(fileName, offset));
14
+ if (!references)
15
15
  return [];
16
- return (0, transforms_1.entriesToLocations)([...entries], ctx);
16
+ const result = [];
17
+ for (const reference of references) {
18
+ if (referenceContext.includeDeclaration) {
19
+ const definition = (0, transforms_1.entryToLocation)(reference.definition, ctx);
20
+ if (definition) {
21
+ result.push(definition);
22
+ }
23
+ }
24
+ for (const referenceEntry of reference.references) {
25
+ const reference = (0, transforms_1.entryToLocation)(referenceEntry, ctx);
26
+ if (reference) {
27
+ result.push(reference);
28
+ }
29
+ }
30
+ }
31
+ return result;
17
32
  };
18
33
  }
19
34
  exports.register = register;
package/out/index.js CHANGED
@@ -421,11 +421,11 @@ function create(ts) {
421
421
  return findImplementations(document.uri, position);
422
422
  });
423
423
  },
424
- provideReferences(document, position, token) {
424
+ provideReferences(document, position, referenceContext, token) {
425
425
  if (!(0, shared_1.isTsDocument)(document) && !(0, shared_1.isJsonDocument)(document))
426
426
  return;
427
427
  return worker(token, () => {
428
- return findReferences(document.uri, position);
428
+ return findReferences(document.uri, position, referenceContext);
429
429
  });
430
430
  },
431
431
  provideFileReferences(document, token) {
@@ -6,6 +6,10 @@ export declare function entriesToLocations(entries: {
6
6
  fileName: string;
7
7
  textSpan: ts.TextSpan;
8
8
  }[], ctx: SharedContext): vscode.Location[];
9
+ export declare function entryToLocation(entry: {
10
+ fileName: string;
11
+ textSpan: ts.TextSpan;
12
+ }, ctx: SharedContext): vscode.Location | undefined;
9
13
  export declare function entriesToLocationLinks<T extends ts.DocumentSpan>(entries: T[], ctx: SharedContext): vscode.LocationLink[];
10
14
  export declare function boundSpanToLocationLinks(info: ts.DefinitionInfoAndBoundSpan, originalDoc: TextDocument, ctx: SharedContext): vscode.LocationLink[];
11
15
  //# sourceMappingURL=transforms.d.ts.map
@@ -1,23 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.boundSpanToLocationLinks = exports.entriesToLocationLinks = exports.entriesToLocations = void 0;
3
+ exports.boundSpanToLocationLinks = exports.entriesToLocationLinks = exports.entryToLocation = exports.entriesToLocations = void 0;
4
4
  function entriesToLocations(entries, ctx) {
5
- const locations = [];
6
- for (const entry of entries) {
7
- const entryUri = ctx.env.fileNameToUri(entry.fileName);
8
- const doc = ctx.getTextDocument(entryUri);
9
- if (!doc)
10
- continue;
11
- const range = {
12
- start: doc.positionAt(entry.textSpan.start),
13
- end: doc.positionAt(entry.textSpan.start + entry.textSpan.length),
14
- };
15
- const location = { uri: entryUri, range };
16
- locations.push(location);
17
- }
18
- return locations;
5
+ return entries
6
+ .map(entry => entryToLocation(entry, ctx))
7
+ .filter((location) => !!location);
19
8
  }
20
9
  exports.entriesToLocations = entriesToLocations;
10
+ function entryToLocation(entry, ctx) {
11
+ const entryUri = ctx.env.fileNameToUri(entry.fileName);
12
+ const doc = ctx.getTextDocument(entryUri);
13
+ if (!doc)
14
+ return;
15
+ const range = {
16
+ start: doc.positionAt(entry.textSpan.start),
17
+ end: doc.positionAt(entry.textSpan.start + entry.textSpan.length),
18
+ };
19
+ const location = { uri: entryUri, range };
20
+ return location;
21
+ }
22
+ exports.entryToLocation = entryToLocation;
21
23
  function entriesToLocationLinks(entries, ctx) {
22
24
  const locations = [];
23
25
  for (const entry of entries) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volar-service-typescript",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "Integrate TypeScript into Volar",
5
5
  "homepage": "https://github.com/volarjs/services/tree/master/packages/typescript",
6
6
  "bugs": "https://github.com/volarjs/services/issues",
@@ -46,5 +46,5 @@
46
46
  "optional": true
47
47
  }
48
48
  },
49
- "gitHead": "54393c9ecc340b229579c534e65ab3b8e097f974"
49
+ "gitHead": "d4023ed503951199b1a9a4b7efe82f4edba42141"
50
50
  }