{"record":{"id":"82a3620cef5d3452","repo":"microsoft/TypeScript","slug":"languageservice-operation-key-not-allowed-in-l-82a362","errorCode":null,"errorMessage":"LanguageService Operation: ${key} not allowed in LanguageServiceMode.Syntactic","messagePattern":"LanguageService Operation: (.+?) not allowed in LanguageServiceMode\\.Syntactic","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/services/services.ts","lineNumber":3471,"sourceCode":"        preparePasteEditsForFile,\r\n        getPasteEdits,\r\n        mapCode,\r\n    };\r\n\r\n    switch (languageServiceMode) {\r\n        case LanguageServiceMode.Semantic:\r\n            break;\r\n        case LanguageServiceMode.PartialSemantic:\r\n            invalidOperationsInPartialSemanticMode.forEach(key =>\r\n                ls[key] = () => {\r\n                    throw new Error(`LanguageService Operation: ${key} not allowed in LanguageServiceMode.PartialSemantic`);\r\n                }\r\n            );\r\n            break;\r\n        case LanguageServiceMode.Syntactic:\r\n            invalidOperationsInSyntacticMode.forEach(key =>\r\n                ls[key] = () => {\r\n                    throw new Error(`LanguageService Operation: ${key} not allowed in LanguageServiceMode.Syntactic`);\r\n                }\r\n            );\r\n            break;\r\n        default:\r\n            Debug.assertNever(languageServiceMode);\r\n    }\r\n    return ls;\r\n}\r\n\r\n/**\r\n * Names in the name table are escaped, so an identifier `__foo` will have a name table entry `___foo`.\r\n *\r\n * @internal\r\n */\r\nexport function getNameTable(sourceFile: SourceFile): Map<__String, number> {\r\n    if (!sourceFile.nameTable) {\r\n        initializeNameTable(sourceFile);\r\n    }\r","sourceCodeStart":3453,"sourceCodeEnd":3489,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/services/services.ts#L3453-L3489","documentation":"Thrown by a LanguageService created in LanguageServiceMode.Syntactic when you call an operation that needs type/semantic information. Syntactic mode (also reachable by passing the legacy boolean true as the third argument to createLanguageService) disables everything in invalidOperationsInSyntacticMode: the entire PartialSemantic list plus getCompletionsAtPosition, getCompletionEntryDetails, getCompletionEntrySymbol, getSignatureHelpItems, getQuickInfoAtPosition, getDefinitionAtPosition, getDefinitionAndBoundSpan, getImplementationAtPosition, getTypeDefinitionAtPosition, getReferencesAtPosition, findReferences, getDocumentHighlights, getNavigateToItems, getRenameInfo, findRenameLocations, getApplicableRefactors, and preparePasteEditsForFile. The most restrictive of the three modes, it parses only — no bound program, no type resolution — so any type-dependent call is replaced with a throwing thunk.","triggerScenarios":"Calling createLanguageService(host, registry, ts.LanguageServiceMode.Syntactic) — or the boolean form createLanguageService(host, registry, true) — then invoking a type-dependent method such as ls.getQuickInfoAtPosition(...), ls.getCompletionsAtPosition(...), ls.getDefinitionAtPosition(...), ls.findRenameLocations(...), or any of the PartialSemantic-listed operations like getSemanticDiagnostics. The interpolated key names the exact method invoked.","commonSituations":"Passing the legacy boolean third arg `true` (which silently maps to Syntactic) instead of undefined/Semantic, expecting full IntelliSense. Using a syntax-only LanguageService (e.g. for fast formatting/outline) but then wiring it up to hover/go-to-definition/completion handlers. Upgrading hosts that previously always created a Semantic service to a configurable mode without updating call sites.","solutions":["Create the LanguageService in Semantic mode: pass undefined (the default) or ts.LanguageServiceMode.Semantic as the third argument, instead of true or ts.LanguageServiceMode.Syntactic.","If using the boolean overload, ensure you pass false (not true) when you want full semantic features.","Maintain separate services: a Syntactic one for outliningSpans/braceMatching/formatting and a Semantic one for completions, quickinfo, definitions, references, rename.","Gate every IntelliSense/diagnostics call behind a check that the service was created in Semantic mode before dispatching."],"exampleFix":"// before (legacy boolean overload: true => Syntactic)\nconst ls = ts.createLanguageService(host, registry, true);\nls.getQuickInfoAtPosition(file, 0); // throws\n\n// after\nconst ls = ts.createLanguageService(host, registry, ts.LanguageServiceMode.Semantic);\nls.getQuickInfoAtPosition(file, 0);","handlingStrategy":"validation","validationCode":"// Avoid the legacy boolean overload ambiguity: be explicit.\nconst mode = ts.LanguageServiceMode.Semantic; // pass undefined for the same default\nconst ls = ts.createLanguageService(host, registry, mode);","typeGuard":"// Everything blocked in Syntactic mode (services.ts:1607) =\n// invalidOperationsInPartialSemanticMode + the syntactic-only additions.\nconst SYNTACTIC_BLOCKED = new Set([\n  \"getSemanticDiagnostics\",\"getSuggestionDiagnostics\",\"getCompilerOptionsDiagnostics\",\n  \"getSemanticClassifications\",\"getEncodedSemanticClassifications\",\n  \"getCodeFixesAtPosition\",\"getCombinedCodeFix\",\"applyCodeActionCommand\",\n  \"organizeImports\",\"getEditsForFileRename\",\"getEmitOutput\",\"getApplicableRefactors\",\n  \"getEditsForRefactor\",\"prepareCallHierarchy\",\"provideCallHierarchyIncomingCalls\",\n  \"provideCallHierarchyOutgoingCalls\",\"provideInlayHints\",\"getSupportedCodeFixes\",\"getPasteEdits\",\n  \"getCompletionsAtPosition\",\"getCompletionEntryDetails\",\"getCompletionEntrySymbol\",\n  \"getSignatureHelpItems\",\"getQuickInfoAtPosition\",\"getDefinitionAtPosition\",\n  \"getDefinitionAndBoundSpan\",\"getImplementationAtPosition\",\"getTypeDefinitionAtPosition\",\n  \"getReferencesAtPosition\",\"findReferences\",\"getDocumentHighlights\",\n  \"getNavigateToItems\",\"getRenameInfo\",\"findRenameLocations\",\"preparePasteEditsForFile\",\n] as const);\nfunction isAllowedInSyntactic(op: string): boolean {\n  return !SYNTACTIC_BLOCKED.has(op as any);\n}","tryCatchPattern":"// Discouraged: catch only as a last resort. The real fix is using Semantic mode.\ntry {\n  ls.getQuickInfoAtPosition(file, offset);\n} catch (e) {\n  if (e instanceof Error && /not allowed in LanguageServiceMode\\.Syntactic/.test(e.message)) {\n    // fall back to a Semantic-mode LanguageService for this request\n  } else throw e;\n}","preventionTips":["Never pass `true` as the third argument to createLanguageService unless you specifically want Syntactic mode; use the enum for clarity.","Reserve Syntactic-mode services for formatting/outline/braceMatching and use a Semantic service for any IntelliSense.","When refactoring mode selection, grep all ls.<method> call sites against the blocked set before flipping the mode."],"tags":["language-service","semantic-mode","intellisense","typescript"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}