@sailshq/language-server 0.6.0 → 0.6.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/index.js +26 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -42,6 +42,17 @@ const documents = new lsp.TextDocuments(TextDocument)
|
|
|
42
42
|
const sailsParser = new SailsParser()
|
|
43
43
|
let typeMap
|
|
44
44
|
|
|
45
|
+
// Helper to check if a document is within the current project
|
|
46
|
+
function isInProject(documentUri) {
|
|
47
|
+
if (!sailsParser.rootDir) return false
|
|
48
|
+
try {
|
|
49
|
+
const documentPath = decodeURIComponent(new URL(documentUri).pathname)
|
|
50
|
+
return documentPath.startsWith(sailsParser.rootDir)
|
|
51
|
+
} catch {
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
45
56
|
connection.onInitialize(async (params) => {
|
|
46
57
|
const rootPath = params.workspaceFolders?.[0]?.uri
|
|
47
58
|
? new URL(params.workspaceFolders[0].uri).pathname
|
|
@@ -92,20 +103,24 @@ connection.onDidChangeWatchedFiles(async (params) => {
|
|
|
92
103
|
typeMap = await sailsParser.buildTypeMap()
|
|
93
104
|
connection.console.log('Type map updated due to file create/delete.')
|
|
94
105
|
|
|
95
|
-
// Re-validate all open documents
|
|
106
|
+
// Re-validate all open documents in the current project
|
|
96
107
|
for (const document of documents.all()) {
|
|
97
|
-
|
|
108
|
+
if (isInProject(document.uri)) {
|
|
109
|
+
validateDocument(connection, document, typeMap)
|
|
110
|
+
}
|
|
98
111
|
}
|
|
99
112
|
}
|
|
100
113
|
})
|
|
101
114
|
|
|
102
115
|
documents.onDidOpen((open) => {
|
|
103
|
-
if (typeMap) {
|
|
116
|
+
if (typeMap && isInProject(open.document.uri)) {
|
|
104
117
|
validateDocument(connection, open.document, typeMap)
|
|
105
118
|
}
|
|
106
119
|
})
|
|
107
120
|
|
|
108
121
|
documents.onDidChangeContent(async (change) => {
|
|
122
|
+
if (!isInProject(change.document.uri)) return
|
|
123
|
+
|
|
109
124
|
const documentUri = change.document.uri
|
|
110
125
|
if (documentUri.includes('api/') || documentUri.includes('config')) {
|
|
111
126
|
typeMap = await sailsParser.buildTypeMap()
|
|
@@ -119,7 +134,7 @@ documents.onDidChangeContent(async (change) => {
|
|
|
119
134
|
|
|
120
135
|
connection.onDefinition(async (params) => {
|
|
121
136
|
const document = documents.get(params.textDocument.uri)
|
|
122
|
-
if (!document) {
|
|
137
|
+
if (!document || !isInProject(params.textDocument.uri)) {
|
|
123
138
|
return null
|
|
124
139
|
}
|
|
125
140
|
|
|
@@ -158,7 +173,7 @@ connection.onDefinition(async (params) => {
|
|
|
158
173
|
|
|
159
174
|
connection.onCompletion(async (params) => {
|
|
160
175
|
const document = documents.get(params.textDocument.uri)
|
|
161
|
-
if (!document) {
|
|
176
|
+
if (!document || !isInProject(params.textDocument.uri)) {
|
|
162
177
|
return null
|
|
163
178
|
}
|
|
164
179
|
const [
|
|
@@ -214,7 +229,12 @@ connection.onCompletion(async (params) => {
|
|
|
214
229
|
return null
|
|
215
230
|
})
|
|
216
231
|
|
|
217
|
-
connection.onCodeAction((params) =>
|
|
232
|
+
connection.onCodeAction((params) => {
|
|
233
|
+
if (!isInProject(params.textDocument.uri)) {
|
|
234
|
+
return []
|
|
235
|
+
}
|
|
236
|
+
return codeActions.getCodeActions(params)
|
|
237
|
+
})
|
|
218
238
|
|
|
219
239
|
connection.onExecuteCommand(async (params) => {
|
|
220
240
|
await codeActions.executeCommand(params, {
|