{"record":{"id":"7cb9932bb242609a","repo":"microsoft/TypeScript","slug":"languageservice-operation-key-not-allowed-in-l","errorCode":null,"errorMessage":"LanguageService Operation: ${key} not allowed in LanguageServiceMode.PartialSemantic","messagePattern":"LanguageService Operation: (.+?) not allowed in LanguageServiceMode\\.PartialSemantic","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/services/services.ts","lineNumber":3464,"sourceCode":"        provideCallHierarchyOutgoingCalls,\r\n        toggleLineComment,\r\n        toggleMultilineComment,\r\n        commentSelection,\r\n        uncommentSelection,\r\n        provideInlayHints,\r\n        getSupportedCodeFixes,\r\n        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","sourceCodeStart":3446,"sourceCodeEnd":3482,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/services/services.ts#L3446-L3482","documentation":"Thrown by a LanguageService created in LanguageServiceMode.PartialSemantic when you call an operation that requires full semantic analysis. On creation, createLanguageService walks the invalidOperationsInPartialSemanticMode list (getSemanticDiagnostics, getSuggestionDiagnostics, getCompilerOptionsDiagnostics, getSemanticClassifications, getEncodedSemanticClassifications, getCodeFixesAtPosition, getCombinedCodeFix, applyCodeActionCommand, organizeImports, getEditsForFileRename, getEmitOutput, getApplicableRefactors, getEditsForRefactor, prepareCallHierarchy, provideCallHierarchyIncomingCalls, provideCallHierarchyOutgoingCalls, provideInlayHints, getSupportedCodeFixes, getPasteEdits) and overwrites each method on the ls object with a thunk that throws. The mode is selected by the third argument to createLanguageService. PartialSemantic mode is intentionally a faster, lighter service that forgoes type info, so those calls are hard-disabled rather than silently returning stale/empty data.","triggerScenarios":"Calling createLanguageService(host, documentRegistry, LanguageServiceMode.PartialSemantic) and then invoking any of the listed semantic methods, e.g. ls.getSemanticDiagnostics(file), ls.getCodeFixesAtPosition(...), ls.organizeImports(...), ls.getEmitOutput(file), ls.getApplicableRefactors(...), ls.provideInlayHints(...), or ls.getPasteEdits(...). The key interpolated into the message is the exact method name you called.","commonSituations":"Editors or language tooling that opt into PartialSemantic (syntax+partial) mode for speed on large projects, then reuse the same ls handle for diagnostics/codefixes/emit that used to work under the default Semantic mode. Migrating a host that previously passed undefined (defaults to Semantic) to an explicit PartialSemantic value. Sharing one ls between a syntactic fast-path and a semantic feature without checking the mode.","solutions":["If you need the failing feature, create the LanguageService in the default Semantic mode by passing undefined (or LanguageServiceMode.Semantic) as the third argument to createLanguageService.","Keep two LanguageService instances: a PartialSemantic one for fast syntactic operations and a Semantic one for diagnostics/codefixes/emit/inlay hints, and route each call to the appropriate instance.","Before calling, check the mode you passed at creation; gate the call behind a guard that only runs semantic operations on a Semantic-mode service.","If you are a tsserver/LS host author, confirm you are not forwarding requests (quickinfo, diagnostics, codefix) to a server configured for PartialSemantic / syntacticOnly."],"exampleFix":"// before\nconst ls = ts.createLanguageService(host, registry, ts.LanguageServiceMode.PartialSemantic);\nls.getSemanticDiagnostics(file); // throws\n\n// after\nconst ls = ts.createLanguageService(host, registry, ts.LanguageServiceMode.Semantic);\nls.getSemanticDiagnostics(file);","handlingStrategy":"validation","validationCode":"// Before creating the service, decide whether you need semantic features.\nconst NEEDS_SEMANTIC = true; // diagnostics, codefixes, emit, inlay hints\nconst mode = NEEDS_SEMANTIC\n  ? ts.LanguageServiceMode.Semantic\n  : ts.LanguageServiceMode.PartialSemantic;\nconst ls = ts.createLanguageService(host, registry, mode);","typeGuard":"// Operations permitted in PartialSemantic mode (everything NOT in\n// invalidOperationsInPartialSemanticMode, services.ts:1585).\nconst PARTIAL_SEMANTIC_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] as const);\nfunction isAllowedInPartialSemantic(op: string): boolean {\n  return !PARTIAL_SEMANTIC_BLOCKED.has(op as any);\n}","tryCatchPattern":"// Not recommended: the throw is a programming error, not a runtime hazard.\n// Prefer creating the service in Semantic mode. If you must defend:\ntry {\n  ls.getSemanticDiagnostics(file);\n} catch (e) {\n  if (e instanceof Error && /not allowed in LanguageServiceMode\\.PartialSemantic/.test(e.message)) {\n    // route to a Semantic-mode service instead\n  } else throw e;\n}","preventionTips":["Treat the third argument to createLanguageService as load-bearing: undefined/Semantic for full features, PartialSemantic only for a deliberately reduced feature set.","Document which LanguageService instance is which mode at the call site so feature handlers dispatch to the correct one.","Keep a single source of truth for the mode and assert the feature you need is in the allowed set before wiring up handlers."],"tags":["language-service","semantic-mode","diagnostics","typescript"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}