Skip to content

Commit 185902c

Browse files
committed
fix: watch dependency files to keep workspace context in sync
1 parent 0109128 commit 185902c

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

extensions/vscode/src/client.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import type { DocumentFilter } from '@volar/vscode'
22
import { middleware } from '@volar/vscode'
33
import { LanguageClient, TransportKind } from '@volar/vscode/node'
4-
import { PACKAGE_JSON_BASENAME, PNPM_WORKSPACE_BASENAME, YARN_WORKSPACE_BASENAME } from 'npmx-language-core/constants'
4+
import { DEPENDENCY_FILE_GLOB } from 'npmx-language-core/constants'
55
import { displayName, extensionId } from 'npmx-shared/meta'
66
import { Hover, MarkdownString } from 'vscode'
77
import { registerRequests } from './request'
88

9-
const SUPPORTED_DOCUMENT_PATTERN = `**/{${PACKAGE_JSON_BASENAME},${PNPM_WORKSPACE_BASENAME},${YARN_WORKSPACE_BASENAME}}`
10-
119
const SUPPORTED_LANGUAGES = [
1210
'javascript',
1311
'typescript',
@@ -60,7 +58,7 @@ export function launch(serverPath: string) {
6058
},
6159
},
6260
documentSelector: [
63-
{ scheme: 'file', pattern: SUPPORTED_DOCUMENT_PATTERN },
61+
{ scheme: 'file', pattern: DEPENDENCY_FILE_GLOB },
6462
...SUPPORTED_LANGUAGES.map((language) => ({ scheme: 'file', language } satisfies DocumentFilter)),
6563
],
6664
markdown: {

packages/language-core/src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ export const PACKAGE_JSON_BASENAME = 'package.json'
22
export const PNPM_WORKSPACE_BASENAME = 'pnpm-workspace.yaml'
33
export const YARN_WORKSPACE_BASENAME = '.yarnrc.yml'
44

5+
export const DEPENDENCY_FILE_GLOB = `**/{${PACKAGE_JSON_BASENAME},${PNPM_WORKSPACE_BASENAME},${YARN_WORKSPACE_BASENAME}}`
6+
57
export const CACHE_MAX_AGE_ONE_DAY = 60 * 60 * 24
68

79
export const NPMX_DEV = 'https://npmx.dev'

packages/language-server/src/workspace.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { IWorkspaceState } from 'npmx-language-service/types'
44
import type { GetPackageManagerRequest } from 'npmx-shared/protocol'
55
import { access, readFile } from 'node:fs/promises'
66
import { RequestType } from '@volar/language-server'
7-
import { PACKAGE_JSON_BASENAME } from 'npmx-language-core/constants'
7+
import { DEPENDENCY_FILE_GLOB, PACKAGE_JSON_BASENAME } from 'npmx-language-core/constants'
88
import { isDependencyFile, isPackageManifest, isWorkspaceFile } from 'npmx-language-core/utils'
99
import { WorkspaceContext } from 'npmx-language-core/workspace'
1010
import { GET_PACKAGE_MANAGER_METHOD } from 'npmx-shared/protocol'
@@ -61,6 +61,10 @@ export class WorkspaceState implements IWorkspaceState {
6161
}
6262

6363
#registerEventListeners() {
64+
this.#server.onInitialized(() => {
65+
this.#server.fileWatcher.watchFiles([DEPENDENCY_FILE_GLOB])
66+
})
67+
6468
this.#server.workspaceFolders.onDidChange(({ removed }) => {
6569
for (const folder of removed) {
6670
const folderUri = URI.parse(folder.uri)

0 commit comments

Comments
 (0)