Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable completions when object recieves zero props #24

Draft
wants to merge 1 commit into
base: release
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions typescript/src/completionsAtPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export const getCompletionsAtPosition = (
const program = languageService.getProgram()
const sourceFile = program?.getSourceFile(fileName)
if (!program || !sourceFile) return
if (!scriptSnapshot || isInBannedPosition(position, fileName, scriptSnapshot, sourceFile, languageService)) return
const node = findChildContainingPosition(ts, sourceFile, position)
if (!scriptSnapshot || isInBannedPosition(position, fileName, scriptSnapshot, sourceFile, languageService, ts, program, node)) return
let prior = languageService.getCompletionsAtPosition(fileName, position, options)
// console.log(
// 'raw prior',
// prior?.entries.map(entry => entry.name),
// )
const node = findChildContainingPosition(ts, sourceFile, position)
if (['.jsx', '.tsx'].some(ext => fileName.endsWith(ext))) {
// JSX Features
if (node) {
Expand Down
13 changes: 13 additions & 0 deletions typescript/src/isInBannedPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@ export default (
scriptSnapshot: tslib.IScriptSnapshot,
sourceFile: tslib.SourceFile,
languageService: tslib.LanguageService,
ts: typeof tslib,
program: tslib.Program,
node?: tslib.Node,
): boolean => {
if (node) {
const typeChecker = program.getTypeChecker()
// TODO check not any!
if (ts.isObjectLiteralExpression(node)) {
const type = typeChecker.getTypeAtLocation(node)
if (type.getProperties().length === 0) {
return true
}
}
}
const { character } = languageService.toLineColumnOffset!(fileName, position)
const textBeforePositionLine = scriptSnapshot?.getText(position - character, position)
const textAfterPositionLine = scriptSnapshot?.getText(position, sourceFile.getLineEndOfPosition(position))
Expand Down