-
Notifications
You must be signed in to change notification settings - Fork 323
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
Small boolean widget tweaks #8994
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,10 @@ import { | |
import { useGraphStore } from '@/stores/graph' | ||
import { requiredImports, type RequiredImport } from '@/stores/graph/imports.ts' | ||
import { useSuggestionDbStore } from '@/stores/suggestionDatabase' | ||
import { type SuggestionEntry } from '@/stores/suggestionDatabase/entry.ts' | ||
import { | ||
type SuggestionEntry, | ||
type SuggestionEntryArgument, | ||
} from '@/stores/suggestionDatabase/entry.ts' | ||
import { Ast } from '@/util/ast' | ||
import type { TokenId } from '@/util/ast/abstract.ts' | ||
import { ArgumentInfoKey } from '@/util/callTree' | ||
|
@@ -136,11 +139,21 @@ watch(selectedIndex, (_index) => { | |
</script> | ||
|
||
<script lang="ts"> | ||
function hasBooleanTagValues(parameter: SuggestionEntryArgument): boolean { | ||
if (parameter.tagValues == null) return false | ||
if (parameter.tagValues.length != 2) return false | ||
const [first, second] = Array.from(parameter.tagValues).sort() | ||
if (first === 'Boolean.False' && second === 'Boolean.True') return true | ||
return false | ||
} | ||
|
||
export const widgetDefinition = defineWidget(WidgetInput.isAstOrPlaceholder, { | ||
priority: 50, | ||
score: (props) => { | ||
if (props.input.dynamicConfig?.kind === 'Single_Choice') return Score.Perfect | ||
if (props.input[ArgumentInfoKey]?.info?.tagValues != null) return Score.Perfect | ||
// Boolean arguments also have tag values, but the checkbox widget should handle them. | ||
if (props.input[ArgumentInfoKey]?.info?.tagValues != null && !hasBooleanTagValues) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we enable some lint for checking it? |
||
return Score.Perfect | ||
return Score.Mismatch | ||
}, | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,37 +221,41 @@ function requiredImportToAst(value: RequiredImport, module?: MutableModule) { | |
} | ||
|
||
/** A list of required imports for specific suggestion entry */ | ||
export function requiredImports(db: SuggestionDb, entry: SuggestionEntry): RequiredImport[] { | ||
export function requiredImports( | ||
db: SuggestionDb, | ||
entry: SuggestionEntry, | ||
directConImport: boolean = false, | ||
): RequiredImport[] { | ||
const unqualifiedImport = (from: QualifiedName): UnqualifiedImport[] => [ | ||
{ | ||
kind: 'Unqualified', | ||
from, | ||
import: entry.name, | ||
}, | ||
] | ||
switch (entry.kind) { | ||
case SuggestionKind.Module: | ||
return entry.reexportedIn | ||
? [ | ||
{ | ||
kind: 'Unqualified', | ||
from: entry.reexportedIn, | ||
import: entry.name, | ||
}, | ||
] | ||
? unqualifiedImport(entry.reexportedIn) | ||
: [ | ||
{ | ||
kind: 'Qualified', | ||
module: entry.definedIn, | ||
}, | ||
] | ||
case SuggestionKind.Type: { | ||
const from = entry.reexportedIn ? entry.reexportedIn : entry.definedIn | ||
return [ | ||
{ | ||
kind: 'Unqualified', | ||
from, | ||
import: entry.name, | ||
}, | ||
] | ||
} | ||
case SuggestionKind.Constructor: { | ||
const selfType = selfTypeEntry(db, entry) | ||
return selfType ? requiredImports(db, selfType) : [] | ||
} | ||
case SuggestionKind.Type: | ||
return unqualifiedImport(entry.reexportedIn ? entry.reexportedIn : entry.definedIn) | ||
case SuggestionKind.Constructor: | ||
if (directConImport) { | ||
return entry.reexportedIn | ||
? unqualifiedImport(entry.reexportedIn) | ||
: entry.memberOf | ||
? unqualifiedImport(entry.memberOf) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m not sure this particular line is correct. IIRC, memberOf would be the module in which the type is defined, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, memberOf is type on which it's defined. The module where the entity is defined is actually |
||
: [] | ||
} else { | ||
const selfType = selfTypeEntry(db, entry) | ||
return selfType ? requiredImports(db, selfType) : [] | ||
} | ||
case SuggestionKind.Method: { | ||
const isStatic = entry.selfType == null | ||
const selfType = selfTypeEntry(db, entry) | ||
|
@@ -272,6 +276,16 @@ export function requiredImports(db: SuggestionDb, entry: SuggestionEntry): Requi | |
} | ||
} | ||
|
||
export function requiredImportsByFQN( | ||
db: SuggestionDb, | ||
fqn: QualifiedName, | ||
directConImport: boolean = false, | ||
) { | ||
const entry = db.getEntryByQualifiedName(fqn) | ||
if (!entry) return [] | ||
return requiredImports(db, entry, directConImport) | ||
} | ||
|
||
function selfTypeEntry(db: SuggestionDb, entry: SuggestionEntry): SuggestionEntry | undefined { | ||
if (entry.memberOf) { | ||
return db.getEntryByQualifiedName(entry.memberOf) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole function could be made simpler by creating some sorts of
arrayEquals
utility and using it here.