@@ -6,15 +6,14 @@ import type { Document, DocumentWithText } from './Document/index.js';
66import { isBinaryDoc } from './Document/isBinaryDoc.js' ;
77import { documentToTextDocument , resolveDocument } from './Document/resolveDocument.js' ;
88import { createTextDocument } from './Models/TextDocument.js' ;
9+ import { toValidationIssueRPC , type ValidationIssueRPC } from './Models/ValidationIssue.js' ;
910import { createPerfTimer } from './perf/index.js' ;
1011import type { ImportFileRefWithError } from './Settings/index.js' ;
11- import { cloneSettingsForExport } from './Settings/sanitizeSettings.js' ;
1212import { determineTextDocumentSettings } from './textValidation/determineTextDocumentSettings.js' ;
1313import type { DocumentValidatorOptions } from './textValidation/index.js' ;
1414import { DocumentValidator } from './textValidation/index.js' ;
1515import { isError } from './util/errors.js' ;
1616import type { Uri } from './util/IUri.js' ;
17- import { memoizeLastCall } from './util/memoizeLastCall.js' ;
1817import { toUri } from './util/Uri.js' ;
1918import type { ValidateTextOptions , ValidationIssue } from './validator.js' ;
2019
@@ -40,6 +39,10 @@ export interface SpellCheckFileOptions extends ValidateTextOptions, Pick<CSpellU
4039 noConfigSearch ?: boolean ;
4140}
4241
42+ export interface SpellCheckFileOptionsRPC extends SpellCheckFileOptions {
43+ measurePerf ?: boolean ;
44+ }
45+
4346export interface SpellCheckFilePerf extends Record < string , number | undefined > {
4447 loadTimeMs ?: number ;
4548 prepareTimeMs ?: number ;
@@ -60,6 +63,28 @@ export interface SpellCheckFileResult {
6063 perf ?: SpellCheckFilePerf ;
6164}
6265
66+ interface DocumentReferenceRPC extends Pick < Document , 'uri' > {
67+ text ?: undefined ;
68+ languageId ?: undefined ;
69+ locale ?: undefined ;
70+ }
71+
72+ export interface SpellCheckFileResultRPC {
73+ /**
74+ * The document that was checked.
75+ *
76+ * **Note:** the text will be missing to avoid sending large amounts of text over the RPC channel.
77+ * If the text is needed, the document should be reloaded using the URI.
78+ */
79+ document : DocumentReferenceRPC ;
80+ issues ?: ValidationIssueRPC [ ] | undefined ;
81+ checked : boolean ;
82+ errors ?: Error [ ] | undefined ;
83+ configErrors ?: ImportFileRefWithError [ ] | undefined ;
84+ dictionaryErrors ?: Map < string , Error [ ] > | undefined ;
85+ perf ?: SpellCheckFilePerf | undefined ;
86+ }
87+
6388/**
6489 * Spell Check a file
6590 * @param file - absolute path to file to read and check.
@@ -135,12 +160,6 @@ export async function spellCheckDocument(
135160 }
136161}
137162
138- const memoizedCloneSettingsForExport = memoizeLastCall ( cloneSettingsForExport ) ;
139-
140- function sanitizeSettingsForExport ( settings : CSpellSettingsWithSourceTrace | undefined ) : CSpellSettingsWithSourceTrace {
141- return settings ? memoizedCloneSettingsForExport ( settings ) : { } ;
142- }
143-
144163/**
145164 * Spell Check a Document.
146165 * @param document - document to be checked. If `document.text` is `undefined` the file will be loaded
@@ -149,11 +168,39 @@ function sanitizeSettingsForExport(settings: CSpellSettingsWithSourceTrace | und
149168 */
150169export async function spellCheckDocumentRPC (
151170 document : Document | DocumentWithText ,
152- options : SpellCheckFileOptions ,
171+ options : SpellCheckFileOptionsRPC ,
153172 settingsOrConfigFile : CSpellUserSettings | ICSpellConfigFile ,
154- ) : Promise < SpellCheckFileResult > {
155- const result = { ...( await spellCheckDocument ( document , options , settingsOrConfigFile ) ) } ;
156- result . settingsUsed = sanitizeSettingsForExport ( result . settingsUsed ) ;
173+ ) : Promise < SpellCheckFileResultRPC > {
174+ const { issues, checked, errors, configErrors, dictionaryErrors, perf } = await spellCheckDocument (
175+ document ,
176+ options ,
177+ settingsOrConfigFile ,
178+ ) ;
179+
180+ const result : SpellCheckFileResultRPC = {
181+ document : { uri : document . uri } ,
182+ checked,
183+ } ;
184+
185+ if ( issues . length ) {
186+ result . issues = issues . map ( toValidationIssueRPC ) ;
187+ }
188+
189+ if ( errors ?. length ) {
190+ result . errors = errors ;
191+ }
192+
193+ if ( configErrors ?. length ) {
194+ result . configErrors = configErrors ;
195+ }
196+ if ( dictionaryErrors ?. size ) {
197+ result . dictionaryErrors = dictionaryErrors ;
198+ }
199+
200+ if ( perf && options . measurePerf ) {
201+ result . perf = perf ;
202+ }
203+
157204 return result ;
158205}
159206
0 commit comments