mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 04:09:28 +00:00
Move getSymbolRange out of class
This commit is contained in:
@@ -105,27 +105,31 @@ export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensP
|
||||
|
||||
(item.childItems || []).forEach(child => this.walkNavTree(document, child, item, results));
|
||||
}
|
||||
protected getSymbolRange(document: vscode.TextDocument, item: Proto.NavigationTree): vscode.Range | null {
|
||||
// TS 3.0+ provides a span for just the symbol
|
||||
if (item.nameSpan) {
|
||||
return typeConverters.Range.fromTextSpan(item.nameSpan);
|
||||
}
|
||||
|
||||
// In older versions, we have to calculate this manually. See #23924
|
||||
const span = item.spans && item.spans[0];
|
||||
if (!span) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const range = typeConverters.Range.fromTextSpan(span);
|
||||
const text = document.getText(range);
|
||||
|
||||
const identifierMatch = new RegExp(`^(.*?(\\b|\\W))${escapeRegExp(item.text || '')}(\\b|\\W)`, 'gm');
|
||||
const match = identifierMatch.exec(text);
|
||||
const prefixLength = match ? match.index + match[1].length : 0;
|
||||
const startOffset = document.offsetAt(new vscode.Position(range.start.line, range.start.character)) + prefixLength;
|
||||
return new vscode.Range(
|
||||
document.positionAt(startOffset),
|
||||
document.positionAt(startOffset + item.text.length));
|
||||
}
|
||||
}
|
||||
|
||||
export function getSymbolRange(
|
||||
document: vscode.TextDocument,
|
||||
item: Proto.NavigationTree
|
||||
): vscode.Range | null {
|
||||
// TS 3.0+ provides a span for just the symbol
|
||||
if (item.nameSpan) {
|
||||
return typeConverters.Range.fromTextSpan(item.nameSpan);
|
||||
}
|
||||
|
||||
// In older versions, we have to calculate this manually. See #23924
|
||||
const span = item.spans && item.spans[0];
|
||||
if (!span) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const range = typeConverters.Range.fromTextSpan(span);
|
||||
const text = document.getText(range);
|
||||
|
||||
const identifierMatch = new RegExp(`^(.*?(\\b|\\W))${escapeRegExp(item.text || '')}(\\b|\\W)`, 'gm');
|
||||
const match = identifierMatch.exec(text);
|
||||
const prefixLength = match ? match.index + match[1].length : 0;
|
||||
const startOffset = document.offsetAt(new vscode.Position(range.start.line, range.start.character)) + prefixLength;
|
||||
return new vscode.Range(
|
||||
document.positionAt(startOffset),
|
||||
document.positionAt(startOffset + item.text.length));
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as PConst from '../protocol.const';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import API from '../utils/api';
|
||||
import { ConfigurationDependentRegistration, VersionDependentRegistration } from '../utils/dependentRegistration';
|
||||
import { CachedNavTreeResponse, ReferencesCodeLens, TypeScriptBaseCodeLensProvider } from './baseCodeLensProvider';
|
||||
import { CachedResponse, ReferencesCodeLens, TypeScriptBaseCodeLensProvider, getSymbolRange } from './baseCodeLensProvider';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
export default class TypeScriptImplementationsCodeLensProvider extends TypeScriptBaseCodeLensProvider {
|
||||
@@ -58,7 +58,7 @@ export default class TypeScriptImplementationsCodeLensProvider extends TypeScrip
|
||||
): vscode.Range | null {
|
||||
switch (item.kind) {
|
||||
case PConst.Kind.interface:
|
||||
return super.getSymbolRange(document, item);
|
||||
return getSymbolRange(document, item);
|
||||
|
||||
case PConst.Kind.class:
|
||||
case PConst.Kind.memberFunction:
|
||||
@@ -66,7 +66,7 @@ export default class TypeScriptImplementationsCodeLensProvider extends TypeScrip
|
||||
case PConst.Kind.memberGetAccessor:
|
||||
case PConst.Kind.memberSetAccessor:
|
||||
if (item.kindModifiers.match(/\babstract\b/g)) {
|
||||
return super.getSymbolRange(document, item);
|
||||
return getSymbolRange(document, item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as PConst from '../protocol.const';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import API from '../utils/api';
|
||||
import { ConfigurationDependentRegistration, VersionDependentRegistration } from '../utils/dependentRegistration';
|
||||
import { CachedNavTreeResponse, ReferencesCodeLens, TypeScriptBaseCodeLensProvider } from './baseCodeLensProvider';
|
||||
import { CachedResponse, ReferencesCodeLens, TypeScriptBaseCodeLensProvider, getSymbolRange } from './baseCodeLensProvider';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -51,7 +51,7 @@ class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLensProvide
|
||||
parent: Proto.NavigationTree | null
|
||||
): vscode.Range | null {
|
||||
if (parent && parent.kind === PConst.Kind.enum) {
|
||||
return super.getSymbolRange(document, item);
|
||||
return getSymbolRange(document, item);
|
||||
}
|
||||
|
||||
switch (item.kind) {
|
||||
@@ -79,7 +79,7 @@ class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLensProvide
|
||||
case PConst.Kind.interface:
|
||||
case PConst.Kind.type:
|
||||
case PConst.Kind.enum:
|
||||
return super.getSymbolRange(document, item);
|
||||
return getSymbolRange(document, item);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user