Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 8461e30

Browse files
committed
renames
1 parent 0d406ee commit 8461e30

File tree

10 files changed

+29
-11
lines changed

10 files changed

+29
-11
lines changed

src/calls/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import { ContextKey } from '../models';
87
import { SymbolsTree } from '../tree';
8+
import { ContextKey } from '../utils';
99
import { CallItem, CallsDirection, CallsTreeInput } from './model';
1010

1111
export function register(tree: SymbolsTree, context: vscode.ExtensionContext): void {

src/calls/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from 'vscode';
77
import { SymbolItemEditorHighlights, SymbolItemNavigation, SymbolTreeInput, SymbolTreeModel } from '../api';
8-
import { del, tail } from '../models';
8+
import { del, tail } from '../utils';
99

1010

1111
export class CallsTreeInput implements SymbolTreeInput {

src/editorHighlights.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import { CallItem, CallsModel, FileItem, ReferencesModel } from './models';
7+
import { CallItem, CallsModel, FileItem, ReferencesModel } from './utils';
88

99
export class EditorHighlights {
1010

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import * as calls from './calls';
99
import { EditorHighlights } from './editorHighlights';
1010
import { History, HistoryItem } from './history';
1111
import * as locations from './locations';
12-
import { CallItem, CallsDirection, CallsModel, Context, FileItem, getPreviewChunks, getRequestRange, ItemSource, ReferenceItem, ReferencesModel, RichCallsDirection } from './models';
1312
import { CallItemDataProvider, HistoryDataProvider, ReferencesProvider, TreeDataProviderWrapper } from './provider';
1413
import { SymbolsTree } from './tree';
14+
import { CallItem, CallsDirection, CallsModel, Context, FileItem, getPreviewChunks, getRequestRange, ItemSource, ReferenceItem, ReferencesModel, RichCallsDirection } from './utils';
1515

1616
export function activate(context: vscode.ExtensionContext) {
1717

src/history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import { Context } from './models';
7+
import { Context } from './utils';
88

99
export class WordAnchor {
1010

src/locations/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from 'vscode';
77
import { SymbolItemEditorHighlights, SymbolItemNavigation, SymbolTreeInput, SymbolTreeModel } from '../api';
8-
import { del, getPreviewChunks, prefixLen, tail } from '../models';
8+
import { del, getPreviewChunks, prefixLen, tail } from '../utils';
99

1010
export class LocationTreeInput implements SymbolTreeInput {
1111

src/navigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from 'vscode';
77
import { SymbolItemNavigation } from './api';
8-
import { ContextKey } from './models';
8+
import { ContextKey } from './utils';
99

1010
export class Navigation {
1111

src/provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from 'vscode';
77
import { History, HistoryItem } from './history';
8-
import { CallItem as CallHierarchyItem, CallsModel, FileItem, getPreviewChunks, ReferenceItem, ReferencesModel } from './models';
8+
import { CallItem as CallHierarchyItem, CallsModel, FileItem, getPreviewChunks, ReferenceItem, ReferencesModel } from './utils';
99

1010
export class ReferencesProvider implements vscode.TreeDataProvider<FileItem | ReferenceItem> {
1111

src/tree.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import * as vscode from 'vscode';
77
import { SymbolTreeInput } from './api';
88
import { EditorHighlights } from './highlights';
99
import { WordAnchor } from './history';
10-
import { ContextKey } from './models';
1110
import { Navigation } from './navigation';
11+
import { ContextKey, isValidRequestPosition } from './utils';
1212

1313
export class SymbolsTree {
1414

@@ -46,6 +46,11 @@ export class SymbolsTree {
4646

4747
async setInput(input: SymbolTreeInput) {
4848

49+
if (!await isValidRequestPosition(input.uri, input.position)) {
50+
this._resetInput();
51+
return;
52+
}
53+
4954
this._ctxInputSource.set(input.contextValue);
5055
this._ctxIsActive.set(true);
5156
this._ctxHasResult.set(true);
@@ -69,8 +74,7 @@ export class SymbolsTree {
6974
}
7075

7176
if (model.empty) {
72-
this.clearInput();
73-
this._tree.message = this._history.size === 0 ? 'No results.' : 'No results. Try running a previous search again:';
77+
this._resetInput();
7478
return;
7579
}
7680

@@ -119,6 +123,11 @@ export class SymbolsTree {
119123
this._tree.message = 'No results.';
120124
}
121125
}
126+
127+
private _resetInput() {
128+
this.clearInput();
129+
this._tree.message = this._history.size === 0 ? 'No results.' : 'No results. Try running a previous search again:';
130+
}
122131
}
123132

124133
// --- tree data

src/models.ts renamed to src/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ export function prefixLen(a: string, b: string): number {
2525
return pos;
2626
}
2727

28+
export async function isValidRequestPosition(uri: vscode.Uri, position: vscode.Position) {
29+
const doc = await vscode.workspace.openTextDocument(uri);
30+
let range = doc.getWordRangeAtPosition(position);
31+
if (!range) {
32+
range = doc.getWordRangeAtPosition(position, /[^\s]+/);
33+
}
34+
return Boolean(range);
35+
}
36+
2837
export function getRequestRange(doc: vscode.TextDocument, pos: vscode.Position): vscode.Range | undefined {
2938
let range = doc.getWordRangeAtPosition(pos);
3039
if (!range) {

0 commit comments

Comments
 (0)