This file provides guidance to WARP (warp.dev) when working with code in this repository.
Sails Language Tools is a monorepo containing a Language Server Protocol (LSP) implementation and VS Code extension for Sails.js development. The project provides IntelliSense, go-to-definition, validation, and diagnostics for Sails.js applications.
This is a monorepo with two main packages:
packages/language-server/- The LSP server that provides all language featurespackages/vscode/- VS Code extension client that communicates with the language server
The language server is built around a central SailsParser class that parses Sails.js projects and builds a comprehensive type map. Key components:
SailsParser.js- Core parser that uses Acorn to analyze JavaScript files and extract metadata about actions, models, helpers, views, policies, and Inertia pagesindex.js- Main LSP server entry point that handles initialization, document sync, completions, and go-to-definition requestscompletions/- 12 completion providers for different Sails.js contexts (actions, models, data types, policies, views, helpers, Inertia pages, etc.)go-to-definitions/- 6 go-to-definition providers for navigating between Sails.js componentsvalidators/- 11 validators that provide real-time diagnostics for common Sails.js errors
The typeMap is rebuilt when files in api/ or config/ directories change, ensuring accurate completions and diagnostics.
src/index.js- Extension activation logic that starts the language client- Bundles both client and server code using Rspack for distribution
- Activates when
.sailsrcfile is detected in workspace - Provides EJS syntax highlighting and language configuration
npm run watchBuilds the VS Code extension in watch mode (runs rspack build --watch in packages/vscode).
npm run buildBuild the VS Code extension for production (in packages/vscode, runs rspack build).
npm run packCreates a .vsix package file for distribution (in packages/vscode).
npm run publishPublishes the VS Code extension to the marketplace (in packages/vscode).
To run the language server standalone:
cd packages/language-server
npm startFor watch mode with auto-restart on changes:
cd packages/language-server
npm run watchThis project uses:
- Prettier for code formatting (configured in
.prettierrc.jswith no semicolons, single quotes, no trailing commas) - Husky for git hooks
- lint-staged to format files on commit
- commitlint with conventional commits format
Prettier runs automatically on staged files via lint-staged. Manual formatting:
npx prettier --write .- Create a new file in
packages/language-server/completions/ - Export a function that takes
(document, position, typeMap)and returns completion items array - Import and call it in
packages/language-server/index.jswithin theonCompletionhandler - Add completion items to the aggregated array
- Create a new file in
packages/language-server/validators/ - Export a function that takes
(document, typeMap)and returns diagnostics array - Import and call it in
packages/language-server/validators/validate-document.js - Add diagnostics to the aggregated array
- Create a new file in
packages/language-server/go-to-definitions/ - Export a function that takes
(document, position, typeMap)and returns location or null - Import and call it in
packages/language-server/index.jswithin theonDefinitionhandler - Add to the Promise.all array and filter for non-null results
The SailsParser class is responsible for discovering and parsing Sails.js project files. To add support for new Sails.js constructs:
- Add parsing methods to
SailsParser.js(private methods use#prefix) - Update
buildTypeMap()method to include new data in the returned typeMap object - The typeMap is automatically rebuilt when files in
api/orconfig/change
Currently, there are no automated tests in this repository. When adding tests:
- Place test files adjacent to the code they test
- Use
.test.jsor.spec.jsnaming convention - Add test script to the relevant package.json
- The extension only activates in workspaces containing a
.sailsrcfile (standard Sails.js project marker) - All language features rely on the typeMap built by SailsParser, which analyzes the project structure at initialization
- The language server expects a standard Sails.js project structure with
api/,config/, andviews/directories - When debugging the extension, the language server runs in a separate process with optional debugging on port 6009