Skip to content

[Playground] Autocomplete#1166

Merged
nex3 merged 34 commits intosass:mainfrom
oddbird:playground-autocomplete
Sep 19, 2024
Merged

[Playground] Autocomplete#1166
nex3 merged 34 commits intosass:mainfrom
oddbird:playground-autocomplete

Conversation

@jamesnw
Copy link
Copy Markdown
Contributor

@jamesnw jamesnw commented Sep 5, 2024

Adds Sass-specific autocomplete to the Playground, specifically-

@netlify
Copy link
Copy Markdown

netlify bot commented Sep 5, 2024

Deploy Preview for sass-lang ready!

Name Link
🔨 Latest commit 2a46d1a
🔍 Latest deploy log https://app.netlify.com/sites/sass-lang/deploys/66eacef0b6238d00092d635b
😎 Deploy Preview https://deploy-preview-1166--sass-lang.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@jamesnw
Copy link
Copy Markdown
Contributor Author

jamesnw commented Sep 6, 2024

@nex3 I have a few options for getting the current list of module functions and variables. Essentially, I'm able to generate a list of the values using Sass, #{map.keys(meta.module-functions("math"))};. To extract it from there, because this will be done in Node on build, I can't use DOM methods to get the values, which would have made this simpler. A few other options-

  1. Use @debug to emit the value to a custom Logger (requires a Sass compilation (or two) per module, but simple parsing)
  2. Use regex to parse the values from CSS. (simplest, but most prone to break) This is the current implementation
  3. Parse the CSS using csstree or @csstools/css-parser-algorithms which is already installed as a dependency of stylelint. (Most robust, but potentially overengineered)

Do you have any preference on this, or other ideas? I didn't see a clear way of parsing this from the existing documentation.

@nex3
Copy link
Copy Markdown
Contributor

nex3 commented Sep 6, 2024

Can you pass the result of map.keys() to a custom function? That seems like the best way to get a JS data structure out of Sass.

@jamesnw jamesnw marked this pull request as ready for review September 9, 2024 17:44
@jamesnw
Copy link
Copy Markdown
Contributor Author

jamesnw commented Sep 9, 2024

Can you pass the result of map.keys() to a custom function? That seems like the best way to get a JS data structure out of Sass.

That worked well!

}

type CompletionInfo = {
name: string;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document members

}
`;

const modMap: ModuleDefinition[] = [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be cleaner to make this a Record<string, ModuleDefinition> with the module names as keys? Then instead of some Array.prototype.reduce stuff, you could use a simpler mapRecord<I, O>(record: Record<T, I>, mapper: (I) => O): Record<T, O> utility function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially it could be cleaner in the cases where I'm reducing things into Record<ModuleName, CompletionSource>, but the metadata is being used in other ways as well. I'm generally a fan of keeping data in flat arrays of objects, as it tends to be the most versatile.

};
}

const moduleVariableCompletions = Object.freeze(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably for a follow-up PR, but it's worth thinking about ways to extract the documentation for variables and functions from source/documentation/modules/*.md so we can include them in these autocompletions.

@jamesnw jamesnw requested a review from nex3 September 13, 2024 19:58
@jamesnw jamesnw requested a review from nex3 September 17, 2024 16:12
@jamesnw jamesnw requested a review from nex3 September 18, 2024 13:01
@nex3 nex3 merged commit fabc033 into sass:main Sep 19, 2024
jgerigmeyer added a commit to oddbird/sass-site that referenced this pull request Sep 20, 2024
* main: (23 commits)
  [Playground] Click to Copy (sass#1177)
  Cut a release for a new Dart Sass version
  [Playground] Debug links (sass#1179)
  Add breaking change page for legacy-js-api (sass#1193)
  [Playground] Autocomplete (sass#1166)
  Add a breaking change page for color functions (sass#1192)
  Remove nonexisting `color.saturate()` function (sass#1190)
  Fix unprefixed `color.adjust()` name (sass#1188)
  Sort color functions alphabetically (sass#1187)
  Document color migrator (sass#1186)
  Cut a release for a new Dart Sass version
  Document new color spaces (sass#1055) (sass#1115)
  Cut a release for a new Dart Sass version
  Bump date-fns from 3.6.0 to 4.0.0 (sass#1181)
  Bump rollup from 4.21.2 to 4.21.3 (sass#1182)
  Bump @codemirror/autocomplete from 6.18.0 to 6.18.1 (sass#1183)
  Bump @typescript-eslint/eslint-plugin from 8.5.0 to 8.6.0 (sass#1185)
  Bump markdown-it-anchor from 9.1.0 to 9.2.0 (sass#1184)
  Fix footer not showing the latest versions. (sass#1178)
  [Playground] Code links (sass#1167)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants