@sailshq/language-server 0.5.0 → 0.5.1
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
|
@@ -8,16 +8,18 @@ const lsp = require('vscode-languageserver/node')
|
|
|
8
8
|
module.exports = function validateModelExist(document, typeMap) {
|
|
9
9
|
const diagnostics = []
|
|
10
10
|
const text = document.getText()
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
modelMap[key.toLowerCase()] = typeMap.models[key]
|
|
16
|
-
}
|
|
11
|
+
const models = typeMap.models || {}
|
|
12
|
+
const lowercasedModelMap = {}
|
|
13
|
+
for (const key of Object.keys(models)) {
|
|
14
|
+
lowercasedModelMap[key.toLowerCase()] = models[key]
|
|
17
15
|
}
|
|
18
16
|
function modelExists(name) {
|
|
19
17
|
if (!name) return false
|
|
20
|
-
return !!
|
|
18
|
+
return !!models[name]
|
|
19
|
+
}
|
|
20
|
+
function modelExistsLowercased(name) {
|
|
21
|
+
if (!name) return false
|
|
22
|
+
return !!lowercasedModelMap[name.toLowerCase()]
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
const knownGlobals = [
|
|
@@ -30,9 +32,9 @@ module.exports = function validateModelExist(document, typeMap) {
|
|
|
30
32
|
'process'
|
|
31
33
|
]
|
|
32
34
|
|
|
33
|
-
// User.find() or User.create() etc
|
|
35
|
+
// User.find() or User.create() etc (only PascalCase identifiers)
|
|
34
36
|
const modelCallRegex =
|
|
35
|
-
/\b([A-Za-z0-9_]
|
|
37
|
+
/\b([A-Z][A-Za-z0-9_]*)\s*\.(?:find|findOne|create|createEach|update|destroy|count|sum|where|findOrCreate)\s*\(/g
|
|
36
38
|
let match
|
|
37
39
|
while ((match = modelCallRegex.exec(text)) !== null) {
|
|
38
40
|
const modelName = match[1]
|
|
@@ -58,7 +60,7 @@ module.exports = function validateModelExist(document, typeMap) {
|
|
|
58
60
|
/sails\.models\.([A-Za-z0-9_]+)\s*\.(?:find|findOne|create|createEach|update|destroy|count|sum|where|findOrCreate)\s*\(/g
|
|
59
61
|
while ((match = sailsModelCallRegex.exec(text)) !== null) {
|
|
60
62
|
const modelName = match[1]
|
|
61
|
-
if (!
|
|
63
|
+
if (!modelExistsLowercased(modelName)) {
|
|
62
64
|
diagnostics.push(
|
|
63
65
|
lsp.Diagnostic.create(
|
|
64
66
|
lsp.Range.create(
|