Skip to content

Commit

Permalink
Merge pull request #80 from zardoy/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy authored Dec 25, 2022
2 parents f922848 + fe9bc4b commit 18dcc3f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"onLanguage:typescriptreact"
],
"scripts": {
"start": "vscode-framework start",
"start": "vscode-framework start --skip-launching",
"build": "tsc && tsc -p typescript --noEmit && vscode-framework build && pnpm build-plugin",
"build-plugin": "node buildTsPlugin.mjs && node buildTsPlugin.mjs --browser",
"watch-plugin": "node buildTsPlugin.mjs --watch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ import { sortBy } from 'rambda'
export default (entries: ts.CompletionEntry[], languageService: ts.LanguageService, c: GetConfig) => {
const ignoreAutoImportsSetting = getIgnoreAutoImportSetting(c)

let newEntries = entries.filter(({ sourceDisplay, name }) => {
if (!sourceDisplay) return true
const ignoreKinds = [ts.ScriptElementKind.warning, ts.ScriptElementKind.string]
entries = entries.filter(({ sourceDisplay, name, kind }) => {
if (!sourceDisplay || ignoreKinds.includes(kind)) return true
const targetModule = ts.displayPartsToString(sourceDisplay)
const toIgnore = isAutoImportEntryShouldBeIgnored(ignoreAutoImportsSetting, targetModule, name)
return !toIgnore
})
// todo I'm not sure of incomplete completion (wasnt tested)
// todo don't forget to impl glob there
const handledSymbolNames = new Set<string>()
for (const [i, entry] of newEntries.entries()) {
for (const [i, entry] of entries.entries()) {
const { name } = entry
if (!entry.sourceDisplay || handledSymbolNames.has(name)) continue
if (!shouldChangeSortingOfAutoImport(name, c)) continue
handledSymbolNames.add(name)
const sortFn = changeSortingOfAutoImport(c, name)
// TODO probably should be rewrited
const entriesToSort: ts.CompletionEntry[] = []
newEntries = newEntries.filter((entry, k) => {
entries = entries.filter((entry, k) => {
if (k < i) return true
if (entry.sourceDisplay && entry.name === name) {
entriesToSort.push(entry)
Expand All @@ -33,7 +34,7 @@ export default (entries: ts.CompletionEntry[], languageService: ts.LanguageServi
})
// todo rewrite outer that for loop to index based and increment here on insert length + handledSymbolNames can be removed in that case
// final one seems to be slow, e.g. it might be slowing down completions
newEntries.splice(i, 0, ...sortBy(({ sourceDisplay }) => sortFn(ts.displayPartsToString(sourceDisplay)), entriesToSort))
entries.splice(i, 0, ...sortBy(({ sourceDisplay }) => sortFn(ts.displayPartsToString(sourceDisplay)), entriesToSort))
}
return newEntries
return entries
}
4 changes: 2 additions & 2 deletions typescript/src/completionsAtPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import objectLiteralCompletions from './completions/objectLiteralCompletions'
import filterJsxElements from './completions/filterJsxComponents'
import markOrRemoveGlobalCompletions from './completions/markOrRemoveGlobalLibCompletions'
import { oneOf } from '@zardoy/utils'
import filterWIthIgnoreAutoImports from './completions/filterWIthIgnoreAutoImports'
import filterWIthIgnoreAutoImports from './completions/ignoreAutoImports'

export type PrevCompletionMap = Record<string, { originalName?: string; documentationOverride?: string | ts.SymbolDisplayPart[] }>

Expand Down Expand Up @@ -177,7 +177,7 @@ export const getCompletionsAtPosition = (
if (node) prior.entries = defaultHelpers(prior.entries, node, languageService) ?? prior.entries
if (exactNode) prior.entries = objectLiteralCompletions(prior.entries, exactNode, languageService, options ?? {}, c) ?? prior.entries
// 90%
if (prior.isGlobalCompletion) prior.entries = filterWIthIgnoreAutoImports(prior.entries, languageService, c)
prior.entries = filterWIthIgnoreAutoImports(prior.entries, languageService, c)

const inKeywordCompletionsResult = inKeywordCompletions(position, node, sourceFile, program, languageService)
if (inKeywordCompletionsResult) {
Expand Down
4 changes: 0 additions & 4 deletions vscode-framework.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ patchPackageJson({

module.exports = defineConfig({
consoleStatements: process.argv.includes('--web') ? false : undefined,
development: {
// @ts-ignore
executable: '---------',
},
target: {
web: true,
desktop: true,
Expand Down

0 comments on commit 18dcc3f

Please sign in to comment.