@sailshq/language-server 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailshq/language-server",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Language Server Protocol server for Sails Language Service",
5
5
  "homepage": "https://sailjs.com",
6
6
  "repository": {
@@ -4,6 +4,13 @@ const walk = require('acorn-walk')
4
4
 
5
5
  module.exports = function validateDataType(document, typeMap) {
6
6
  const diagnostics = []
7
+ const documentUri = document.uri
8
+
9
+ // Only validate files in backend directories where data types are relevant
10
+ if (!documentUri.includes('/api/') && !documentUri.includes('/scripts/')) {
11
+ return diagnostics
12
+ }
13
+
7
14
  const text = document.getText()
8
15
 
9
16
  try {
@@ -4,6 +4,13 @@ const walk = require('acorn-walk')
4
4
 
5
5
  module.exports = function validateHelperInputExist(document, typeMap) {
6
6
  const diagnostics = []
7
+ const documentUri = document.uri
8
+
9
+ // Only validate files in backend directories where helpers are accessible
10
+ if (!documentUri.includes('/api/') && !documentUri.includes('/scripts/')) {
11
+ return diagnostics
12
+ }
13
+
7
14
  const text = document.getText()
8
15
 
9
16
  try {
@@ -130,6 +130,13 @@ function validateCriteriaAttributes(
130
130
  */
131
131
  module.exports = function validateModelAttributeExist(document, typeMap) {
132
132
  const diagnostics = []
133
+ const documentUri = document.uri
134
+
135
+ // Only validate files in backend directories where models are accessible
136
+ if (!documentUri.includes('/api/') && !documentUri.includes('/scripts/')) {
137
+ return diagnostics
138
+ }
139
+
133
140
  const text = document.getText()
134
141
 
135
142
  // Build a lowercased model map for robust case-insensitive lookup
@@ -7,17 +7,26 @@ const lsp = require('vscode-languageserver/node')
7
7
  */
8
8
  module.exports = function validateModelExist(document, typeMap) {
9
9
  const diagnostics = []
10
+ const documentUri = document.uri
11
+
12
+ // Only validate files in backend directories where models are accessible
13
+ if (!documentUri.includes('/api/') && !documentUri.includes('/scripts/')) {
14
+ return diagnostics
15
+ }
16
+
10
17
  const text = document.getText()
11
- // Build a lowercased model map for robust case-insensitive lookup
12
- const modelMap = {}
13
- if (typeMap.models) {
14
- for (const key of Object.keys(typeMap.models)) {
15
- modelMap[key.toLowerCase()] = typeMap.models[key]
16
- }
18
+ const models = typeMap.models || {}
19
+ const lowercasedModelMap = {}
20
+ for (const key of Object.keys(models)) {
21
+ lowercasedModelMap[key.toLowerCase()] = models[key]
17
22
  }
18
23
  function modelExists(name) {
19
24
  if (!name) return false
20
- return !!modelMap[name.toLowerCase()]
25
+ return !!models[name]
26
+ }
27
+ function modelExistsLowercased(name) {
28
+ if (!name) return false
29
+ return !!lowercasedModelMap[name.toLowerCase()]
21
30
  }
22
31
 
23
32
  const knownGlobals = [
@@ -30,9 +39,9 @@ module.exports = function validateModelExist(document, typeMap) {
30
39
  'process'
31
40
  ]
32
41
 
33
- // User.find() or User.create() etc
42
+ // User.find() or User.create() etc (only PascalCase identifiers)
34
43
  const modelCallRegex =
35
- /\b([A-Za-z0-9_]+)\s*\.(?:find|findOne|create|createEach|update|destroy|count|sum|where|findOrCreate)\s*\(/g
44
+ /\b([A-Z][A-Za-z0-9_]*)\s*\.(?:find|findOne|create|createEach|update|destroy|count|sum|where|findOrCreate)\s*\(/g
36
45
  let match
37
46
  while ((match = modelCallRegex.exec(text)) !== null) {
38
47
  const modelName = match[1]
@@ -58,7 +67,7 @@ module.exports = function validateModelExist(document, typeMap) {
58
67
  /sails\.models\.([A-Za-z0-9_]+)\s*\.(?:find|findOne|create|createEach|update|destroy|count|sum|where|findOrCreate)\s*\(/g
59
68
  while ((match = sailsModelCallRegex.exec(text)) !== null) {
60
69
  const modelName = match[1]
61
- if (!modelExists(modelName)) {
70
+ if (!modelExistsLowercased(modelName)) {
62
71
  diagnostics.push(
63
72
  lsp.Diagnostic.create(
64
73
  lsp.Range.create(
@@ -2,6 +2,12 @@ const lsp = require('vscode-languageserver/node')
2
2
 
3
3
  module.exports = function validatePageExist(document, typeMap) {
4
4
  const diagnostics = []
5
+ const documentUri = document.uri
6
+
7
+ // Only validate files in api/ where Inertia pages are referenced
8
+ if (!documentUri.includes('/api/')) {
9
+ return diagnostics
10
+ }
5
11
 
6
12
  const pages = extractPageReferences(document)
7
13
  for (const { page, range } of pages) {
@@ -4,6 +4,13 @@ const walk = require('acorn-walk')
4
4
 
5
5
  module.exports = function validateRequiredHelperInput(document, typeMap) {
6
6
  const diagnostics = []
7
+ const documentUri = document.uri
8
+
9
+ // Only validate files in backend directories where helpers are accessible
10
+ if (!documentUri.includes('/api/') && !documentUri.includes('/scripts/')) {
11
+ return diagnostics
12
+ }
13
+
7
14
  const text = document.getText()
8
15
 
9
16
  try {
@@ -2,6 +2,13 @@ const lsp = require('vscode-languageserver/node')
2
2
 
3
3
  module.exports = function validateRequiredModelAttribute(document, typeMap) {
4
4
  const diagnostics = []
5
+ const documentUri = document.uri
6
+
7
+ // Only validate files in backend directories where models are accessible
8
+ if (!documentUri.includes('/api/') && !documentUri.includes('/scripts/')) {
9
+ return diagnostics
10
+ }
11
+
5
12
  const text = document.getText()
6
13
  const models = typeMap.models || {}
7
14