-
Notifications
You must be signed in to change notification settings - Fork 12.9k
8000
Show file tree
Hide file tree
May 13, 2020
May 13, 2020
May 13, 2020
Jun 12, 2020
Jun 12, 2020
Jun 12, 2020
Jun 16, 2020
Jun 16, 2020
8000
Syntax only server creates inferred project with all the open files w… #38561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5726838
Syntax only server creates inferred project with all the open files w…
sheetalkamat ffe50a3
No Watching
sheetalkamat 90d8a96
Disable tests
sheetalkamat cb638d9
Merge branch 'master' into syntaxAsSemanticServer
sheetalkamat 807c008
Add and fix tests
sheetalkamat 89127a5
Only support selected commands
sheetalkamat 3e1a3c2
Revert "Disable tests"
sheetalkamat 901cfc3
Dont log request details for unsupported commands
sheetalkamat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -1171,6 +1171,26 @@ namespace ts { | |
} | ||
} | ||
|
||
const invalidOperationsOnSyntaxOnly: readonly (keyof LanguageService)[] = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this relate to the list in session.ts? Do they need to stay in sync? Is one redundant? |
||
"getSyntacticDiagnostics", | ||
"getSemanticDiagnostics", | ||
"getSuggestionDiagnostics", | ||
"getCompilerOptionsDiagnostics", | ||
"getSemanticClassifications", | ||
"getEncodedSemanticClassifications", | ||
"getCodeFixesAtPosition", | ||
"getCombinedCodeFix", | ||
"applyCodeActionCommand", | ||
"organizeImports", | ||
"getEditsForFileRename", | ||
"getEmitOutput", | ||
"getApplicableRefactors", | ||
"getEditsForRefactor", | ||
"prepareCallHierarchy", | ||
"provideCallHierarchyIncomingCalls", | ||
"provideCallHierarchyOutgoingCalls", | ||
]; | ||
|
||
export function createLanguageService( | ||
host: LanguageServiceHost, | ||
documentRegistry: DocumentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory()), | ||
|
@@ -1224,8 +1244,6 @@ namespace ts { | |
} | ||
|
||
function synchronizeHostData(): void { | ||
Debug.assert(!syntaxOnly); | ||
|
||
// perform fast check if host supports it | ||
if (host.getProjectVersion) { | ||
const hostProjectVersion = host.getProjectVersion(); | ||
|
@@ -1419,11 +1437,6 @@ namespace ts { | |
|
||
// TODO: GH#18217 frequently asserted as defined | ||
function getProgram(): Program | undefined { | ||
if (syntaxOnly) { | ||
Debug.assert(program === undefined); | ||
return undefined; | ||
} | ||
|
||
synchronizeHostData(); | ||
|
||
return program; | ||
|
@@ -2199,7 +2212,7 @@ namespace ts { | |
return declaration ? CallHierarchy.getOutgoingCalls(program, declaration) : []; | ||
} | ||
|
||
return { | ||
const ls: LanguageService = { | ||
dispose, | ||
cleanupSemanticCache, | ||
getSyntacticDiagnostics, | ||
|
@@ -2259,6 +2272,16 @@ namespace ts { | |
provideCallHierarchyIncomingCalls, | ||
provideCallHierarchyOutgoingCalls | ||
}; | ||
|
||
if (syntaxOnly) { | ||
invalidOperationsOnSyntaxOnly.forEach(key => | ||
ls[key] = () => { | ||
throw new Error(`LanguageService Operation: ${key} not allowed on syntaxServer`); | ||
} | ||
); | ||
} | ||
|
||
return ls; | ||
} | ||
|
||
/* @internal */ | ||
|
This file contains hidden or 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 hidden or 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
98 changes: 98 additions & 0 deletions
98
src/testRunner/unittests/tsserver/semanticOperationsOnSyntaxServer.ts
This file contains hidden or 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,98 @@ | ||
namespace ts.projectSystem { | ||
describe("unittests:: tsserver:: Semantic operations on Syntax server", () => { | ||
function setup() { | ||
const file1: File = { | ||
path: `${tscWatch.projectRoot}/a.ts`, | ||
content: `import { y } from "./b"; | ||
class c { prop = "hello"; foo() { return this.prop; } }` | ||
}; | ||
const file2: File = { | ||
path: `${tscWatch.projectRoot}/b.ts`, | ||
content: "export const y = 10;" | ||
}; | ||
const configFile: File = { | ||
path: `${tscWatch.projectRoot}/tsconfig.json`, | ||
content: "{}" | ||
}; | ||
const host = createServerHost([file1, file2, libFile, configFile]); | ||
const session = createSession(host, { syntaxOnly: true, useSingleInferredProject: true }); | ||
return { host, session, file1, file2, configFile }; | ||
} | ||
|
||
it("open files are added to inferred project even if config file is present and semantic operations succeed", () => { | ||
const { host, session, file1, file2 } = setup(); | ||
const service = session.getProjectService(); | ||
openFilesForSession([file1], session); | ||
checkNumberOfProjects(service, { inferredProjects: 1 }); | ||
const project = service.inferredProjects[0]; | ||
checkProjectActualFiles(project, [libFile.path, file1.path]); // Import is not resolved | ||
verifyCompletions(); | ||
|
||
openFilesForSession([file2], session); | ||
checkNumberOfProjects(service, { inferredProjects: 1 }); | ||
checkProjectActualFiles(project, [libFile.path, file1.path, file2.path]); | ||
verifyCompletions(); | ||
|
||
function verifyCompletions() { | ||
assert.isTrue(project.languageServiceEnabled); | ||
checkWatchedFiles(host, emptyArray); | ||
checkWatchedDirectories(host, emptyArray, /*recursive*/ true); | ||
checkWatchedDirectories(host, emptyArray, /*recursive*/ false); | ||
const response = session.executeCommandSeq<protocol.CompletionsRequest>({ | ||
command: protocol.CommandTypes.Completions, | ||
arguments: protocolFileLocationFromSubstring(file1, "prop", { index: 1 }) | ||
}).response as protocol.CompletionEntry[]; | ||
assert.deepEqual(response, [ | ||
completionEntry("foo", ScriptElementKind.memberFunctionElement), | ||
completionEntry("prop", ScriptElementKind.memberVariableElement), | ||
]); | ||
} | ||
|
||
function completionEntry(name: string, kind: ScriptElementKind): protocol.CompletionEntry { | ||
return { | ||
name, | ||
kind, | ||
kindModifiers: "", | ||
s 9583 ortText: Completions.SortText.LocationPriority, | ||
hasAction: undefined, | ||
insertText: undefined, | ||
isRecommended: undefined, | ||
replacementSpan: undefined, | ||
source: undefined | ||
}; | ||
} | ||
}); | ||
|
||
it("throws on unsupported commands", () => { | ||
const { session, file1 } = setup(); | ||
const service = session.getProjectService(); | ||
openFilesForSession([file1], session); | ||
let hasException = false; | ||
const request: protocol.SemanticDiagnosticsSyncRequest = { | ||
type: "request", | ||
seq: 1, | ||
command: protocol.CommandTypes.SemanticDiagnosticsSync, | ||
arguments: { file: file1.path } | ||
}; | ||
try { | ||
session.executeCommand(request); | ||
} | ||
catch (e) { | ||
assert.equal(e.message, `Request: semanticDiagnosticsSync not allowed on syntaxServer`); | ||
hasException = true; | ||
} | ||
assert.isTrue(hasException); | ||
|
||
hasException = false; | ||
const project = service.inferredProjects[0]; | ||
try { | ||
project.getLanguageService().getSemanticDiagnostics(file1.path); | ||
} | ||
catch (e) { | ||
assert.equal(e.message, `LanguageService Operation: getSemanticDiagnostics not allowed on syntaxServer`); | ||
hasException = true; | ||
} | ||
assert.isTrue(hasException); | ||
}); | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SyntacticDiagnosticsSync: This is somewhat project setting dependent ? Atleast at some point parsing errors use to be different based on target .. eg target determines what unicode is considered identifier start... So i am not sure if this should be enabled.. But if we do enable we i was wondering if GetErr should only do syntax checks and skip semantic and suggetion diagnostics on syntax server
Some questionable which i have disabled for now
Reload
ReloadProjects
PrepareCallHierarchy
ProvideCallHierarchyIncomingCalls
ProvideCallHierarchyOutgoingCalls