-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1287 from Quramy/use_provided_typescript_module
chore: Use provided TypeScript module
- Loading branch information
Showing
33 changed files
with
163 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import ts from 'typescript'; | ||
import type ts from '../tsmodule'; | ||
import { | ||
parse, | ||
visit, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/graphql-language-service-adapter/get-completion-at-position.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/graphql-language-service-adapter/get-definition-and-bound-span.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/graphql-language-service-adapter/get-quick-info-at-position.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src/graphql-language-service-adapter/get-semantic-diagnostics.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/graphql-language-service-adapter/graphql-language-service-adapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import type ts from 'typescript/lib/tsserverlibrary'; | ||
import type { TsGraphQLPluginConfigOptions } from '../types'; | ||
import { GraphQLLanguageServiceAdapter } from '../graphql-language-service-adapter'; | ||
import { SchemaManagerFactory, createSchemaManagerHostFromLSPluginInfo } from '../schema-manager'; | ||
import { FragmentRegistry } from '../gql-ast-util'; | ||
import { | ||
createScriptSourceHelper, | ||
registerDocumentChangeEvent, | ||
getTemplateNodeUnder, | ||
findAllNodes, | ||
getSanitizedTemplateText, | ||
createFileNameFilter, | ||
parseTagConfig, | ||
} from '../ts-ast-util'; | ||
import { LanguageServiceProxyBuilder } from './language-service-proxy-builder'; | ||
|
||
export function create(info: ts.server.PluginCreateInfo): ts.LanguageService { | ||
const logger = (msg: string) => info.project.projectService.logger.info(`[ts-graphql-plugin] ${msg}`); | ||
logger('config: ' + JSON.stringify(info.config)); | ||
const schemaManager = new SchemaManagerFactory(createSchemaManagerHostFromLSPluginInfo(info)).create(); | ||
const { schema, errors: schemaErrors } = schemaManager.getSchema(); | ||
const config = info.config as TsGraphQLPluginConfigOptions; | ||
const tag = parseTagConfig(config.tag); | ||
const removeDuplicatedFragments = config.removeDuplicatedFragments === false ? false : true; | ||
const enabledGlobalFragments = config.enabledGlobalFragments !== false; | ||
const isExcluded = createFileNameFilter({ specs: config.exclude, projectName: info.project.getProjectName() }); | ||
|
||
const fragmentRegistry = new FragmentRegistry({ logger }); | ||
if (enabledGlobalFragments) { | ||
const handleAcquireOrUpdate = (fileName: string, sourceFile: ts.SourceFile, version: string) => { | ||
fragmentRegistry.registerDocuments( | ||
fileName, | ||
version, | ||
findAllNodes(sourceFile, node => getTemplateNodeUnder(node, tag)).map(node => | ||
getSanitizedTemplateText(node, sourceFile), | ||
), | ||
); | ||
}; | ||
|
||
registerDocumentChangeEvent( | ||
// Note: | ||
// documentRegistry in ts.server.Project is annotated @internal | ||
(info.project as any).documentRegistry as ts.DocumentRegistry, | ||
{ | ||
onAcquire: (fileName, sourceFile, version) => { | ||
if (!isExcluded(fileName) && info.languageServiceHost.getScriptFileNames().includes(fileName)) { | ||
handleAcquireOrUpdate(fileName, sourceFile, version); | ||
} | ||
}, | ||
onUpdate: (fileName, sourceFile, version) => { | ||
if (!isExcluded(fileName) && info.languageServiceHost.getScriptFileNames().includes(fileName)) { | ||
if (fragmentRegistry.getFileCurrentVersion(fileName) === version) return; | ||
handleAcquireOrUpdate(fileName, sourceFile, version); | ||
} | ||
}, | ||
onRelease: fileName => { | ||
fragmentRegistry.removeDocument(fileName); | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
const scriptSourceHelper = createScriptSourceHelper(info, { exclude: config.exclude }); | ||
const adapter = new GraphQLLanguageServiceAdapter(scriptSourceHelper, { | ||
schema, | ||
schemaErrors, | ||
logger, | ||
tag, | ||
fragmentRegistry, | ||
removeDuplicatedFragments, | ||
}); | ||
|
||
const proxy = new LanguageServiceProxyBuilder(info) | ||
.wrap('getCompletionsAtPosition', delegate => adapter.getCompletionAtPosition.bind(adapter, delegate)) | ||
.wrap('getSemanticDiagnostics', delegate => adapter.getSemanticDiagnostics.bind(adapter, delegate)) | ||
.wrap('getQuickInfoAtPosition', delegate => adapter.getQuickInfoAtPosition.bind(adapter, delegate)) | ||
.wrap('getDefinitionAndBoundSpan', delegate => adapter.getDefinitionAndBoundSpan.bind(adapter, delegate)) | ||
.wrap('getDefinitionAtPosition', delegate => adapter.getDefinitionAtPosition.bind(adapter, delegate)) | ||
.build(); | ||
|
||
schemaManager.registerOnChange(adapter.updateSchema.bind(adapter)); | ||
schemaManager.start(); | ||
|
||
return proxy; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,9 @@ | ||
import ts from 'typescript/lib/tsserverlibrary'; | ||
import type { TsGraphQLPluginConfigOptions } from '../types'; | ||
import { GraphQLLanguageServiceAdapter } from '../graphql-language-service-adapter'; | ||
import { SchemaManagerFactory, createSchemaManagerHostFromLSPluginInfo } from '../schema-manager'; | ||
import { FragmentRegistry } from '../gql-ast-util'; | ||
import { | ||
createScriptSourceHelper, | ||
registerDocumentChangeEvent, | ||
getTemplateNodeUnder, | ||
findAllNodes, | ||
getSanitizedTemplateText, | ||
createFileNameFilter, | ||
parseTagConfig, | ||
} from '../ts-ast-util'; | ||
import { LanguageServiceProxyBuilder } from './language-service-proxy-builder'; | ||
import type ts from 'typescript/lib/tsserverlibrary'; | ||
|
||
function create(info: ts.server.PluginCreateInfo): ts.LanguageService { | ||
const logger = (msg: string) => info.project.projectService.logger.info(`[ts-graphql-plugin] ${msg}`); | ||
logger('config: ' + JSON.stringify(info.config)); | ||
const schemaManager = new SchemaManagerFactory(createSchemaManagerHostFromLSPluginInfo(info)).create(); | ||
const { schema, errors: schemaErrors } = schemaManager.getSchema(); | ||
const config = info.config as TsGraphQLPluginConfigOptions; | ||
const tag = parseTagConfig(config.tag); | ||
const removeDuplicatedFragments = config.removeDuplicatedFragments === false ? false : true; | ||
const enabledGlobalFragments = config.enabledGlobalFragments !== false; | ||
const isExcluded = createFileNameFilter({ specs: config.exclude, projectName: info.project.getProjectName() }); | ||
import { setModule } from './ts-server-module'; | ||
|
||
const fragmentRegistry = new FragmentRegistry({ logger }); | ||
if (enabledGlobalFragments) { | ||
const handleAcquireOrUpdate = (fileName: string, sourceFile: ts.SourceFile, version: string) => { | ||
fragmentRegistry.registerDocuments( | ||
fileName, | ||
version, | ||
findAllNodes(sourceFile, node => getTemplateNodeUnder(node, tag)).map(node => | ||
getSanitizedTemplateText(node, sourceFile), | ||
), | ||
); | ||
}; | ||
|
||
registerDocumentChangeEvent( | ||
// Note: | ||
// documentRegistry in ts.server.Project is annotated @internal | ||
(info.project as any).documentRegistry as ts.DocumentRegistry, | ||
{ | ||
onAcquire: (fileName, sourceFile, version) => { | ||
if (!isExcluded(fileName) && info.languageServiceHost.getScriptFileNames().includes(fileName)) { | ||
handleAcquireOrUpdate(fileName, sourceFile, version); | ||
} | ||
}, | ||
onUpdate: (fileName, sourceFile, version) => { | ||
if (!isExcluded(fileName) && info.languageServiceHost.getScriptFileNames().includes(fileName)) { | ||
if (fragmentRegistry.getFileCurrentVersion(fileName) === version) return; | ||
handleAcquireOrUpdate(fileName, sourceFile, version); | ||
} | ||
}, | ||
onRelease: fileName => { | ||
fragmentRegistry.removeDocument(fileName); | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
const scriptSourceHelper = createScriptSourceHelper(info, { exclude: config.exclude }); | ||
const adapter = new GraphQLLanguageServiceAdapter(scriptSourceHelper, { | ||
schema, | ||
schemaErrors, | ||
logger, | ||
tag, | ||
fragmentRegistry, | ||
removeDuplicatedFragments, | ||
}); | ||
|
||
const proxy = new LanguageServiceProxyBuilder(info) | ||
.wrap('getCompletionsAtPosition', delegate => adapter.getCompletionAtPosition.bind(adapter, delegate)) | ||
.wrap('getSemanticDiagnostics', delegate => adapter.getSemanticDiagnostics.bind(adapter, delegate)) | ||
.wrap('getQuickInfoAtPosition', delegate => adapter.getQuickInfoAtPosition.bind(adapter, delegate)) | ||
.wrap('getDefinitionAndBoundSpan', delegate => adapter.getDefinitionAndBoundSpan.bind(adapter, delegate)) | ||
.wrap('getDefinitionAtPosition', delegate => adapter.getDefinitionAtPosition.bind(adapter, delegate)) | ||
.build(); | ||
|
||
schemaManager.registerOnChange(adapter.updateSchema.bind(adapter)); | ||
schemaManager.start(); | ||
|
||
return proxy; | ||
} | ||
|
||
export const pluginModuleFactory: ts.server.PluginModuleFactory = () => { | ||
export const pluginModuleFactory: ts.server.PluginModuleFactory = ({ typescript }) => { | ||
setModule(typescript); | ||
const { create } = require('./create-plugin') as typeof import('./create-plugin'); | ||
return { create }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type ts from 'typescript/lib/tsserverlibrary'; | ||
|
||
let _module: typeof ts; | ||
|
||
export function setModule(typescript: typeof ts) { | ||
_module = typescript; | ||
} | ||
|
||
export function getModule() { | ||
return _module; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import ts from 'typescript'; | ||
import ts from '../tsmodule'; | ||
|
||
export const astf = ts.factory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-restricted-imports | ||
import * as ts from 'typescript'; | ||
export = ts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { getModule } = require('./language-service-plugin/ts-server-module'); | ||
|
||
module.exports = getModule() ?? require('typescript'); |
Oops, something went wrong.