Skip to content

Commit 86c6e0e

Browse files
authored
v0.0.101 (#30)
2 parents f69d49c + e7a72b4 commit 86c6e0e

File tree

8 files changed

+109
-5
lines changed

8 files changed

+109
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ experiment-*
2323
src/generated.ts
2424

2525
.vscode-test
26+
.vscode-test-web
2627
.eslintcache
2728
Thumbs.db
2829
.idea/

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@
259259
{
260260
"command": "insertTypeDecoration",
261261
"title": "Insert Type Decoration"
262+
},
263+
{
264+
"command": "openReferencesInView",
265+
"title": "Open References in View"
262266
}
263267
],
264268
"configuration": {
@@ -459,6 +463,11 @@
459463
"type": "boolean",
460464
"description": "Wether to references on highlighted JS keywords in vue/javascript/typescript/html",
461465
"default": true
466+
},
467+
"statusbarOccurrencesCount": {
468+
"type": "boolean",
469+
"description": "Wether to display statusbar with all occurences count (including selected) in the following format: E (case matching occurences)",
470+
"default": false
462471
}
463472
}
464473
},

src/extension.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ import completionsKindPlayground from './features/completionsKindPlayground'
5757
import autoEscapeJson from './features/autoEscapeJson'
5858
import gitStageQuickPick from './features/gitStageQuickPick'
5959
import githubEnvTerminal from './features/githubEnvTerminal'
60-
import indentEmptyLineOnClick from './features/indentEmptyLineOnClick'
60+
import indentEmptyLineOnClick from './features/autoIndentEmptyLine'
6161
import openOutlineItemInNewEditor from './features/openOutlineItemInNewEditor'
6262
import insertFileName from './features/insertFileName'
6363
import tsPluginIntegrations from './features/tsPluginIntegrations'
6464
import goToHighlightedLocations from './features/goToHighlightedLocations'
6565
import tsHighlightedKeywordsReferences from './features/tsHighlightedKeywordsReferences'
6666
import autoRenameJsx from './features/autoRenameJsx'
67+
import openReferencesInView from './features/openReferencesInView'
68+
import statusbarOccurrencesCount from './features/statusbarOccurrencesCount'
6769

6870
export const activate = () => {
6971
void initGitApi()
@@ -130,6 +132,8 @@ export const activate = () => {
130132
goToHighlightedLocations()
131133
tsHighlightedKeywordsReferences()
132134
autoRenameJsx()
135+
openReferencesInView()
136+
statusbarOccurrencesCount()
133137

134138
// vscode.languages.registerSelectionRangeProvider('*', {
135139
// provideSelectionRanges(document, positions, token) {

src/features/indentEmptyLineOnClick.ts renamed to src/features/autoIndentEmptyLine.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ export default () => {
66
const autoIndentEmptyLine = getExtensionSetting('autoIndentEmptyLine')
77
if (autoIndentEmptyLine === 'disabled') return
88
vscode.window.onDidChangeTextEditorSelection(async ({ textEditor, selections, kind }) => {
9-
if (getActiveRegularEditor()?.document.uri !== textEditor.document.uri) return
9+
const { document } = textEditor
10+
if (getActiveRegularEditor()?.document.uri !== document.uri) return
1011
if (kind === undefined || kind === vscode.TextEditorSelectionChangeKind.Command) return
11-
if (!getExtensionSetting('autoIndentEmptyLineIfNotDirty') && !textEditor.document.isDirty) return
12+
if (!getExtensionSetting('autoIndentEmptyLineIfNotDirty') && !document.isDirty) return
1213
if (autoIndentEmptyLine === 'mouse-only' && kind !== vscode.TextEditorSelectionChangeKind.Mouse) return
1314
const firstSelection = selections[0]!
14-
if (selections.length !== 1 || !firstSelection.start.isEqual(firstSelection.end) || firstSelection.start.character !== 0) return
15+
if (
16+
selections.length !== 1 ||
17+
!firstSelection.start.isEqual(firstSelection.end) ||
18+
firstSelection.start.character !== 0 ||
19+
document.lineAt(firstSelection.start).text.trim().length > 0
20+
)
21+
return
1522
await vscode.commands.executeCommand('editor.action.reindentselectedlines')
1623
})
1724
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as vscode from 'vscode'
2+
import { registerExtensionCommand } from 'vscode-framework'
3+
4+
export default () => {
5+
registerExtensionCommand('openReferencesInView', async () => {
6+
const { activeTextEditor } = vscode.window
7+
if (!activeTextEditor) return
8+
const {
9+
document: { uri },
10+
selection: { active: position },
11+
} = activeTextEditor
12+
const result: vscode.Location[] = await vscode.commands.executeCommand('vscode.executeReferenceProvider', uri, position)
13+
if (!result) return
14+
15+
// chill https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/languageFeatures/fileReferences.ts#L69
16+
const config = vscode.workspace.getConfiguration('references')
17+
const existingSetting = config.inspect<string>('preferredLocation')
18+
19+
await config.update('preferredLocation', 'view')
20+
try {
21+
await vscode.commands.executeCommand('editor.action.showReferences', uri, new vscode.Position(0, 0), result)
22+
} finally {
23+
await config.update('preferredLocation', existingSetting?.workspaceFolderValue ?? existingSetting?.workspaceValue)
24+
}
25+
})
26+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as vscode from 'vscode'
2+
import { getExtensionSetting } from 'vscode-framework'
3+
4+
export default () => {
5+
if (!getExtensionSetting('statusbarOccurrencesCount')) return
6+
const statusbar = vscode.window.createStatusBarItem('occurrencesCount', vscode.StatusBarAlignment.Right, 1000)
7+
statusbar.name = 'Occurrences Count'
8+
const update = () => {
9+
let hide = true
10+
try {
11+
const { activeTextEditor } = vscode.window
12+
if (!activeTextEditor) return
13+
14+
const { document, selection, selections } = activeTextEditor
15+
if (selection.start.isEqual(selection.end)) return
16+
const selectionText = document.getText(selection)
17+
if (selections.length > 1 && selections.some(selection => document.getText(selection) !== selectionText)) return
18+
const allOccurrencesCount = document.getText().split(selectionText).length - 1
19+
statusbar.text = `E ${allOccurrencesCount}`
20+
hide = false
21+
statusbar.show()
22+
} finally {
23+
if (hide) statusbar.hide()
24+
}
25+
}
26+
27+
vscode.window.onDidChangeActiveTextEditor(update)
28+
vscode.window.onDidChangeTextEditorSelection(({ textEditor }) => {
29+
if (textEditor.document.uri !== vscode.window.activeTextEditor?.document.uri) return
30+
update()
31+
})
32+
update()
33+
}

src/features/tsHighlightedKeywordsReferences.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default () => {
1010
if (!wordRange) return
1111
const word = document.getText(wordRange)
1212
// already works with `this`
13-
const allowList = 'return async await if else for while break continue try catch finally'.split(' ')
13+
const allowList = 'return async await if else for while break continue try catch finally switch case export'.split(' ')
1414
if (!allowList.includes(word)) return
1515
const highlights: vscode.DocumentHighlight[] | undefined =
1616
(await vscode.commands.executeCommand('vscode.executeDocumentHighlights', document.uri, position)) ?? []

src/futureFeatures.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,28 @@ const unusedCommands = () => {
185185
}
186186
})
187187
})
188+
registerNoop('Auto rename on type', () => {
189+
vscode.languages.registerLinkedEditingRangeProvider('*', {
190+
async provideLinkedEditingRanges(document, position, token) {
191+
if (document.uri.scheme === 'output') return
192+
const highlights: vscode.DocumentHighlight[] | undefined =
193+
(await vscode.commands.executeCommand('vscode.executeDocumentHighlights', document.uri, position)) ?? []
194+
const definitions: vscode.Location[] | vscode.LocationLink[] | undefined =
195+
(await vscode.commands.executeCommand('vscode.executeDefinitionProvider', document.uri, position)) ?? []
196+
if (!definitions) return
197+
const thisDefinitions = definitions
198+
.map(item => (item instanceof vscode.Location ? [item.uri, item.range] : [item.targetUri, item.targetRange]))
199+
.filter(res => {
200+
const [uri, range] = res as [vscode.Uri, vscode.Range]
201+
return uri.toString() === document.uri.toString() && range.contains(position)
202+
})
203+
if (thisDefinitions.length > 0)
204+
return {
205+
ranges: highlights.map(({ range }) => range),
206+
wordPattern: undefined,
207+
}
208+
return undefined
209+
},
210+
})
211+
})
188212
}

0 commit comments

Comments
 (0)