Skip to content

Commit 7b2ba84

Browse files
authored
Merge pull request #162 from zardoy/develop
2 parents da99f2e + b4b1f3b commit 7b2ba84

37 files changed

+554
-236
lines changed

.vscode/launch.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"${workspaceFolder}/out/**/*.js"
1515
],
1616
"sourceMaps": true,
17+
"cascadeTerminateToConfigurations": [
18+
"Attach to TS Server",
19+
],
1720
"env": {
1821
"TSS_DEBUG": "9223",
1922
"TSS_REMOTE_DEBUG": "9223"
@@ -25,6 +28,7 @@
2528
"request": "attach",
2629
"restart": true,
2730
"port": 9223,
31+
"customDescriptionGenerator": "function (def) { return this?.__debugKind || this?.__debugFlags || def }",
2832
"sourceMaps": true,
2933
"outFiles": [
3034
"${workspaceFolder}/out/**/*.js"
@@ -49,6 +53,13 @@
4953
"Launch Extension",
5054
"Attach to TS Server"
5155
]
52-
}
56+
},
57+
{
58+
"name": "Extension + Volar",
59+
"configurations": [
60+
"Launch Extension",
61+
"Attach to Vue Semantic Server"
62+
]
63+
},
5364
]
5465
}

README.MD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ TOC:
1616
- [Contributed Code Actions](#contributed-code-actions)
1717
- [Even Even More](#even-even-more)
1818

19-
> *Note*: You can disable all optional features with `> Disable All Optional Features` setting right after install.
19+
> *Note*: You can disable all optional features with `> Disable All Optional Features` command right after install.
2020
>
2121
> *Note*: Visit website for list of recommended settings: <https://ts-plugin.zardoy.com/>
2222
@@ -42,7 +42,7 @@ Also is not supported in the web.
4242

4343
90% work done in this extension highly improves completions experience!
4444

45-
### Strict Emmet
45+
### Strict JSX Emmet
4646

4747
(*enabled by default*) when react langs are in `emmet.excludeLanguages`
4848

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
{
6363
"command": "replaceGlobalTypescriptWithLocalVersion",
6464
"title": "Replace Global Typescript with Local Version"
65+
},
66+
{
67+
"command": "getArgumentReferencesFromCurrentParameter",
68+
"title": "Get Argument References from Current Parameter"
6569
}
6670
],
6771
"keybindings": [
@@ -201,4 +205,4 @@
201205
"runTest": false
202206
}
203207
}
204-
}
208+
}

playground.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
import ts from 'typescript/lib/tsserverlibrary'
33
import { createLanguageService } from './typescript/src/dummyLanguageService'
44

5-
let testString = 'const a: {/** @default test */a: 5} | {b: 6, /** yes */a: 9} = null as any;\nif ("||" in a) {}'
5+
globalThis.ts = ts
6+
7+
let testString = /* ts */ `
8+
const b = () => 5
9+
const a = b()|| as
10+
new Promise()
11+
`
612
const replacement = '||'
713
const pos = testString.indexOf(replacement)
814
testString = testString.slice(0, pos) + testString.slice(pos + replacement.length)
@@ -16,7 +22,7 @@ const sourceFile = program?.getSourceFile(filePath)
1622
if (!program || !sourceFile) throw new Error('No source file')
1723

1824
const typeChecker = program.getTypeChecker()
19-
const node = findChildContainingPosition(ts, sourceFile, pos)
25+
let node = findChildContainingPosition(ts, sourceFile, pos)
2026
if (!node) throw new Error('No node')
2127
const type = typeChecker.getTypeAtLocation(node)
2228

pnpm-lock.yaml

Lines changed: 5 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/apiCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const sharedApiRequest = async (type: TriggerCharacterCommand, { offset,
2727
if (!position) offset ??= document.offsetAt(activeTextEditor!.selection.active) + relativeOffset
2828
const requestOffset = offset ?? document.offsetAt(position!)
2929
const requestPos = position ?? document.positionAt(offset!)
30-
const getData = async () => sendCommand(type, { document: document!, position: requestPos })
30+
const getData = async () => sendCommand(type, { document: document!, position: requestPos, inputOptions: {} })
3131
const CACHE_UNDEFINED_TIMEOUT = 1000
3232
if (cacheableCommands.has(type as any)) {
3333
const cacheEntry = operationsCache.get(type)

src/codeActionProvider.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode'
22
import { defaultJsSupersetLangsWithVue } from '@zardoy/vscode-utils/build/langs'
33
import { registerExtensionCommand, showQuickPick, getExtensionSetting, getExtensionCommandId } from 'vscode-framework'
44
import { compact } from '@zardoy/utils'
5-
import { RequestResponseTypes, RequestOptionsTypes } from '../typescript/src/ipcTypes'
5+
import { RequestOutputTypes, RequestInputTypes } from '../typescript/src/ipcTypes'
66
import { sendCommand } from './sendCommand'
77
import { tsTextChangesToVscodeTextEdits, vscodeRangeToTs, tsTextChangesToVscodeSnippetTextEdits } from './util'
88

@@ -26,7 +26,7 @@ export default () => {
2626
return
2727
}
2828

29-
const fixAllEdits = await sendCommand<RequestResponseTypes['getFixAllEdits']>('getFixAllEdits', {
29+
const fixAllEdits = await sendCommand('getFixAllEdits', {
3030
document,
3131
})
3232
if (!fixAllEdits || token.isCancellationRequested) return
@@ -89,16 +89,13 @@ export default () => {
8989
async resolveCodeAction(codeAction: ExtendedCodeAction, token) {
9090
const { document } = codeAction
9191
if (!document) throw new Error('Unresolved code action without document')
92-
const result = await sendCommand<RequestResponseTypes['getExtendedCodeActionEdits'], RequestOptionsTypes['getExtendedCodeActionEdits']>(
93-
'getExtendedCodeActionEdits',
94-
{
95-
document,
96-
inputOptions: {
97-
applyCodeActionTitle: codeAction.title,
98-
range: vscodeRangeToTs(document, codeAction.diagnostics?.length ? codeAction.diagnostics[0]!.range : codeAction.requestRange),
99-
},
92+
const result = await sendCommand('getExtendedCodeActionEdits', {
93+
document,
94+
inputOptions: {
95+
applyCodeActionTitle: codeAction.title,
96+
range: vscodeRangeToTs(document, codeAction.diagnostics?.length ? codeAction.diagnostics[0]!.range : codeAction.requestRange),
10097
},
101-
)
98+
})
10299
if (!result) throw new Error('No code action edits. Try debug.')
103100
const { edits = [], snippetEdits = [] } = result
104101
const workspaceEdit = new vscode.WorkspaceEdit()
@@ -111,9 +108,9 @@ export default () => {
111108
},
112109
})
113110

114-
registerExtensionCommand('applyRefactor' as any, async (_, arg?: RequestResponseTypes['getTwoStepCodeActions']) => {
111+
registerExtensionCommand('applyRefactor' as any, async (_, arg?: RequestOutputTypes['getTwoStepCodeActions']) => {
115112
if (!arg) return
116-
let sendNextData: RequestOptionsTypes['twoStepCodeActionSecondStep']['data'] | undefined
113+
let sendNextData: RequestInputTypes['twoStepCodeActionSecondStep']['data'] | undefined
117114
const { turnArrayIntoObject } = arg
118115
if (turnArrayIntoObject) {
119116
const { keysCount, totalCount, totalObjectCount } = turnArrayIntoObject
@@ -151,7 +148,7 @@ export default () => {
151148
})
152149

153150
async function getPossibleTwoStepRefactorings(range: vscode.Range, document = vscode.window.activeTextEditor!.document) {
154-
return sendCommand<RequestResponseTypes['getTwoStepCodeActions'], RequestOptionsTypes['getTwoStepCodeActions']>('getTwoStepCodeActions', {
151+
return sendCommand('getTwoStepCodeActions', {
155152
document,
156153
position: range.start,
157154
inputOptions: {
@@ -161,16 +158,13 @@ export default () => {
161158
}
162159

163160
async function getSecondStepRefactoringData(range: vscode.Range, secondStepData?: any, document = vscode.window.activeTextEditor!.document) {
164-
return sendCommand<RequestResponseTypes['twoStepCodeActionSecondStep'], RequestOptionsTypes['twoStepCodeActionSecondStep']>(
165-
'twoStepCodeActionSecondStep',
166-
{
167-
document,
168-
position: range.start,
169-
inputOptions: {
170-
range: vscodeRangeToTs(document, range),
171-
data: secondStepData,
172-
},
161+
return sendCommand('twoStepCodeActionSecondStep', {
162+
document,
163+
position: range.start,
164+
inputOptions: {
165+
range: vscodeRangeToTs(document, range),
166+
data: secondStepData,
173167
},
174-
)
168+
})
175169
}
176170
}

src/emmet.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as vscode from 'vscode'
22
import { compact } from '@zardoy/utils'
33
import { getExtensionSetting, registerExtensionCommand } from 'vscode-framework'
4-
import { EmmetResult } from '../typescript/src/ipcTypes'
54
import { sendCommand } from './sendCommand'
65
import { Configuration } from './configurationType'
76

@@ -29,7 +28,7 @@ export const registerEmmet = async () => {
2928
const cursorOffset: number = document.offsetAt(position)
3029

3130
if (context.triggerKind !== vscode.CompletionTriggerKind.TriggerForIncompleteCompletions || !lastStartOffset) {
32-
const result = await sendCommand<EmmetResult>('emmet-completions', { document, position })
31+
const result = await sendCommand('emmet-completions', { document, position })
3332
if (!result) {
3433
lastStartOffset = undefined
3534
return

src/extension.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/* eslint-disable @typescript-eslint/no-require-imports */
22
import * as vscode from 'vscode'
33
import { defaultJsSupersetLangs } from '@zardoy/vscode-utils/build/langs'
4-
import { Settings, extensionCtx, getExtensionSetting, getExtensionSettingId, registerExtensionCommand } from 'vscode-framework'
4+
import { extensionCtx, getExtensionSetting, getExtensionSettingId } from 'vscode-framework'
55
import { pickObj } from '@zardoy/utils'
66
import { watchExtensionSettings } from '@zardoy/vscode-utils/build/settings'
7-
import { ConditionalPick } from 'type-fest'
87
import webImports from './webImports'
98
import { sendCommand } from './sendCommand'
109
import { registerEmmet } from './emmet'
@@ -27,13 +26,21 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted
2726
isActivated = true
2827
let webWaitingForConfigSync = false
2928

29+
const getResolvedConfig = () => {
30+
const configuration = vscode.workspace.getConfiguration()
31+
const config: any = {
32+
...configuration.get(process.env.IDS_PREFIX!),
33+
editorSuggestInsertModeReplace: configuration.get('editor.suggest.insertMode') === 'replace',
34+
}
35+
mergeSettingsFromScopes(config, 'typescript', extensionCtx.extension.packageJSON)
36+
return config
37+
}
38+
3039
const syncConfig = () => {
3140
if (!tsApi) return
3241
console.log('sending configure request for typescript-essential-plugins')
33-
const config: any = { ...vscode.workspace.getConfiguration().get(process.env.IDS_PREFIX!) }
3442
// todo implement language-specific settings
35-
mergeSettingsFromScopes(config, 'typescript', extensionCtx.extension.packageJSON)
36-
43+
const config = getResolvedConfig()
3744
tsApi.configurePlugin('typescript-essential-plugins', config)
3845

3946
if (process.env.PLATFORM === 'node') {
@@ -50,7 +57,7 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted
5057
}
5158

5259
vscode.workspace.onDidChangeConfiguration(async ({ affectsConfiguration }) => {
53-
if (affectsConfiguration(process.env.IDS_PREFIX!)) {
60+
if (affectsConfiguration(process.env.IDS_PREFIX!) || affectsConfiguration('editor.suggest.insertMode')) {
5461
syncConfig()
5562
if (
5663
process.env.PLATFORM === 'node' &&
@@ -72,8 +79,8 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted
7279
if (!activeTextEditor || !vscode.languages.match(defaultJsSupersetLangs, activeTextEditor.document)) return
7380
if (!webWaitingForConfigSync) return
7481
// webWaitingForConfigSync = false
75-
const config = vscode.workspace.getConfiguration().get(process.env.IDS_PREFIX!)
76-
void sendCommand(`updateConfig${JSON.stringify(config)}` as any)
82+
const config = getResolvedConfig()
83+
void sendCommand(`updateConfig${JSON.stringify(config)}` as any, { inputOptions: {} })
7784
}
7885

7986
vscode.window.onDidChangeActiveTextEditor(possiblySyncConfig)

src/onCompletionAccepted.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,37 @@ export default (tsApi: { onCompletionAccepted }) => {
6262
const nextChar = editor.document.getText(new vscode.Range(startPos, startPos.translate(0, 1)))
6363
if (!params || ['(', '.', '`'].includes(nextChar)) return
6464

65-
if (isAmbiguous && lastAcceptedAmbiguousMethodSnippetSuggestion !== suggestionName) {
66-
lastAcceptedAmbiguousMethodSnippetSuggestion = suggestionName
67-
return
68-
}
65+
if (getExtensionSetting('methodSnippetsInsertText') === 'disable') {
66+
// handle insertion only if it wasn't handled by methodSnippetsInsertText already
67+
if (isAmbiguous && lastAcceptedAmbiguousMethodSnippetSuggestion !== suggestionName) {
68+
lastAcceptedAmbiguousMethodSnippetSuggestion = suggestionName
69+
return
70+
}
6971

70-
const replaceArguments = getExtensionSetting('methodSnippets.replaceArguments')
71-
72-
const snippet = new vscode.SnippetString('')
73-
snippet.appendText('(')
74-
// todo maybe when have optional (skipped), add a way to leave trailing , with tabstop (previous behavior)
75-
for (const [i, param] of params.entries()) {
76-
const replacer = replaceArguments[param.replace(/\?$/, '')]
77-
if (replacer === null) continue
78-
if (replacer) {
79-
useReplacer(snippet, replacer)
80-
} else {
81-
snippet.appendPlaceholder(param)
72+
const replaceArguments = getExtensionSetting('methodSnippets.replaceArguments')
73+
74+
const snippet = new vscode.SnippetString('')
75+
snippet.appendText('(')
76+
// todo maybe when have optional (skipped), add a way to leave trailing , with tabstop (previous behavior)
77+
for (const [i, param] of params.entries()) {
78+
const replacer = replaceArguments[param.replace(/\?$/, '')]
79+
if (replacer === null) continue
80+
if (replacer) {
81+
useReplacer(snippet, replacer)
82+
} else {
83+
snippet.appendPlaceholder(param)
84+
}
85+
86+
if (i !== params.length - 1) snippet.appendText(', ')
8287
}
8388

84-
if (i !== params.length - 1) snippet.appendText(', ')
89+
snippet.appendText(')')
90+
void editor.insertSnippet(snippet, undefined, {
91+
undoStopAfter: false,
92+
undoStopBefore: false,
93+
})
8594
}
8695

87-
snippet.appendText(')')
88-
void editor.insertSnippet(snippet, undefined, {
89-
undoStopAfter: false,
90-
undoStopBefore: false,
91-
})
9296
if (vscode.workspace.getConfiguration('editor.parameterHints').get('enabled') && params.length > 0) {
9397
void vscode.commands.executeCommand('editor.action.triggerParameterHints')
9498
}

0 commit comments

Comments
 (0)