-
Notifications
You must be signed in to change notification settings - Fork 0
Add getSuggestionsLikeVariable #42
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
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,10 +14,11 @@ | |||||||||||
| // import {properties, stories} from '@primer/primitives/dist/js/intellisense' | ||||||||||||
| import camelCase from 'lodash.camelcase' | ||||||||||||
| import {isColor} from './utils/is-color' | ||||||||||||
| import {getSuggestions} from './suggestions' | ||||||||||||
| import {getSuggestions, getSuggestionsLikeVariable, type SuggestionWithSortText} from './suggestions' | ||||||||||||
| import {getCssVariable} from './utils/get-css-variable' | ||||||||||||
| import {getVariableInfo} from './utils/get-variable-info' | ||||||||||||
| import {getDocumentation} from './documentation' | ||||||||||||
| import {getCurrentWord} from './utils/get-current-word' | ||||||||||||
|
|
||||||||||||
| // Create a connection for the server, using Node's IPC as a transport. | ||||||||||||
| // Also include all preview / proposed LSP features. | ||||||||||||
|
|
@@ -67,12 +68,25 @@ | |||||||||||
| let property: string = ast.nodes[0].type === 'decl' ? camelCase(ast.nodes[0].prop) : undefined | ||||||||||||
| if (!property) return [] | ||||||||||||
|
|
||||||||||||
| const value: string = | ||||||||||||
| ast.nodes[0].type === 'decl' ? ast.nodes[0].value.replace(');', '').replace('\n', '').trim() : undefined | ||||||||||||
|
siddharthkp marked this conversation as resolved.
|
||||||||||||
|
|
||||||||||||
| const suggestedVariablesWithSortText: SuggestionWithSortText[] = [] | ||||||||||||
|
|
||||||||||||
| // if the cursor is at the css variable, get getSuggestionsLikeVariable instead of getSuggestions(property) | ||||||||||||
| const document = documents.get(params.textDocument.uri) | ||||||||||||
| const offset = document.offsetAt(params.position) | ||||||||||||
| const currentWord = getCurrentWord(document, offset) | ||||||||||||
|
||||||||||||
| const document = documents.get(params.textDocument.uri) | |
| const offset = document.offsetAt(params.position) | |
| const currentWord = getCurrentWord(document, offset) | |
| const offset = doc.offsetAt(params.position) | |
| const currentWord = getCurrentWord(doc, offset) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,9 +1,19 @@ | ||||||
| import {describe, it, expect} from 'vitest' | ||||||
| import {getSuggestions} from './suggestions' | ||||||
| import {getSuggestions, getSuggestionsLikeVariable} from './suggestions' | ||||||
|
|
||||||
| describe('Suggestions', () => { | ||||||
| it('returns suggestions for paddingBottom', () => { | ||||||
| const suggestions = getSuggestions('paddingBottom') | ||||||
| expect(suggestions).toMatchSnapshot() | ||||||
| }) | ||||||
|
|
||||||
| it('returns suggestions for variable part: --fgColor', () => { | ||||||
| const suggestions = getSuggestionsLikeVariable('--fgColor') | ||||||
|
||||||
| const suggestions = getSuggestionsLikeVariable('--fgColor') | |
| const suggestions = getSuggestionsLikeVariable('fgColor') |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,9 @@ import {propertiesMap, aliases, type Suggestion} from './data' | |||||||||||||
| // eslint-disable-next-line import/no-namespace | ||||||||||||||
| import type * as CSS from 'csstype' | ||||||||||||||
|
|
||||||||||||||
| export const getSuggestions = (property: keyof CSS.Properties) => { | ||||||||||||||
| export type SuggestionWithSortText = Suggestion & {sortText: string} | ||||||||||||||
|
|
||||||||||||||
| export const getSuggestions = (property: keyof CSS.Properties): SuggestionWithSortText[] => { | ||||||||||||||
| // TODO: for shorthands, property might be the second property like borderColor or paddingInline | ||||||||||||||
| // we can be smarter about this | ||||||||||||||
| let suggestedVariables: Suggestion[] | ||||||||||||||
|
|
@@ -24,6 +26,22 @@ export const getSuggestions = (property: keyof CSS.Properties) => { | |||||||||||||
|
|
||||||||||||||
| if (!suggestedVariables) return [] | ||||||||||||||
|
|
||||||||||||||
| const suggestedVariablesWithSortText = sortSuggestions(suggestedVariables) | ||||||||||||||
| return suggestedVariablesWithSortText | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // slower than getSuggestions, use judiciously | ||||||||||||||
| export const getSuggestionsLikeVariable = (variableQuery: string): SuggestionWithSortText[] => { | ||||||||||||||
| const allVariables = flatten(Object.values(propertiesMap)) | ||||||||||||||
| const suggestedVariables: Suggestion[] = allVariables.filter(variable => variable.name.includes(variableQuery)) | ||||||||||||||
|
Comment on lines
+34
to
+36
|
||||||||||||||
| export const getSuggestionsLikeVariable = (variableQuery: string): SuggestionWithSortText[] => { | |
| const allVariables = flatten(Object.values(propertiesMap)) | |
| const suggestedVariables: Suggestion[] = allVariables.filter(variable => variable.name.includes(variableQuery)) | |
| const ALL_VARIABLES: Suggestion[] = flatten(Object.values(propertiesMap)) | |
| export const getSuggestionsLikeVariable = (variableQuery: string): SuggestionWithSortText[] => { | |
| const suggestedVariables: Suggestion[] = ALL_VARIABLES.filter(variable => variable.name.includes(variableQuery)) |
Uh oh!
There was an error while loading. Please reload this page.